// Write sends a new log message to the writer. This implements the loggo.Writer interface.
346701
func (w *BufferedLogWriter) Write(entry loggo.Entry) {
	w.in <- &LogRecord{
		Time:     entry.Timestamp,
		Module:   entry.Module,
		Location: fmt.Sprintf("%s:%d", filepath.Base(entry.Filename), entry.Line),
		Level:    entry.Level,
		Message:  entry.Message,
	}
}
206406
func Write(w io.Writer, message io.Reader, order binary.ByteOrder) (i int, err error) {
	data, err := ioutil.ReadAll(message)
	if err != nil {
		return 0, err
	}

	header := make([]byte, messageSizeInBytes)
	order.PutUint32(header, uint32(len(data)))
	return w.Write(append(header, data...))
}
857358
func (s *SyslogWrapper) Write(p []byte) (int, error) {
	// Skip syslog if the log level doesn't apply
	if !s.filt.Check(p) {
		return 0, nil
	}

	// Extract log level
	var level string
	afterLevel := p
	x := bytes.IndexByte(p, '[')
	if x >= 0 {
		y := bytes.IndexByte(p[x:], ']')
		if y >= 0 {
			level = string(p[x+1 : x+y])
			afterLevel = p[x+y+2:]
		}
	}

	// Each log level will be handled by a specific syslog priority
	priority, ok := levelPriority[level]
	if !ok {
		priority = gsyslog.LOG_NOTICE
	}

	// Attempt the write
	err := s.l.WriteLevel(priority, afterLevel)
	return len(p), err
}
846735
func (l *LogFile) Write(b []byte) (n int, err error) {
	// Filter out log entries that do not match log level criteria
	if !l.logFilter.Check(b) {
		return 0, nil
	}

	l.acquire.Lock()
	defer l.acquire.Unlock()
	//Create a new file if we have no file to write to
	if l.FileInfo == nil {
		if err := l.openNew(); err != nil {
			return 0, err
		}
	}
	// Check for the last contact and rotate if necessary
	if err := l.rotate(); err != nil {
		return 0, err
	}
	l.BytesWritten += int64(len(b))
	return l.FileInfo.Write(b)
}
921095
func (ctx *Context) Write(s []byte) (int, error) {
	if ctx.Logger != nil {
		return ctx.Logger.Write(s)
	}
	return len(s), nil
}
653528
func (w *Writer) Write(b []byte) (int, error) {
	if w.priority > LOG_DEBUG || w.priority < LOG_EMERG {
		return 0, errors.New("log/syslog: invalid priority")
	}
	return w.conn.writeBytes(w.priority, w.prefix, b)
}
710306
func (w *etmWriter) Write(b []byte) (int, error) {
	if err := w.WriteMsg(b); err != nil {
		return 0, err
	}
	return len(b), nil
}
1053443
func Writer(unit string, l kitlog.Logger) io.WriteCloser {
	l = kitlog.With(l, "unit", unit)
	pr, pw := io.Pipe()
	go func() {
		s := bufio.NewScanner(pr)
		for s.Scan() {
			l.Log("msg", s.Text())
		}
		if err := s.Err(); err != nil {
			l.Log("msg", "scanner error", "err", err)
		}
	}()
	return pw
}
637811
func (l *bunyanLog) write(stream Stream, level int) error {
	data := make([]byte, 0)
	argl := len(l.args)

	if argl == 0 {
		return nil
	}

	d := make(map[string]interface{})
	d["v"] = 0
	d["level"] = level
	d["name"] = stream.Name
	d["hostname"] = l.logger.hostname
	d["pid"] = os.Getppid()
	d["time"] = nowTimestamp()

	// add static fields first
	for key, value := range l.logger.staticFields {
		if canSetField(key) {
			d[key] = l.serialize(key, value)
		}
	}

	// add passed fields/data last
	if argl == 1 && typeName(l.args[0]) == "string" {
		// if 1 argument that is a string, the string is the msg
		d["msg"] = l.serialize("msg", l.args[0])
	} else if isError(l.args[0]) {
		// if the first argument is an error, set error field with string value of error
		d["error"] = l.serialize("error", l.args[0])
		if argl == 2 {
			d["msg"] = l.serialize("msg", l.args[1])
		} else if argl > 2 {
			d["msg"] = l.serialize("msg", l.sprintf(l.args[1:]))
		}
	} else if isHashMap(l.args[0]) {
		// if the first argument is a hashmap, process its values
		for key, value := range l.args[0].(map[string]interface{}) {
			if canSetField(key) {
				d[key] = l.serialize(key, value)
			}
		}
		if argl == 2 {
			d["msg"] = l.serialize("msg", l.args[1])
		} else if argl > 2 {
			d["msg"] = l.serialize("msg", l.sprintf(l.args[1:]))
		}
	} else {
		d["msg"] = l.serialize("msg", l.sprintf(l.args))
	}

	// marshal the json
	if jsonData, err := json.Marshal(d); err != nil {
		return err
	} else {
		data = []byte(fmt.Sprintf("%s\n", string(jsonData)))
	}

	switch stream.Type {
	case LogTypeStream:
		return l.writeStream(stream, data)
	case LogTypeFile:
		return l.writeFile(stream, data)
	case LogTypeRotatingFile:
		return l.writeRotatingFile(stream, data)
	case LogTypeRaw:
		return l.writeStream(stream, data)
	}
	return nil
}
880351
func (w LogWriter) Write(bytes []byte) (int, error) {
	if len(bytes) > 0 {
		return fmt.Fprint(Output, Yellow.Regular("["), time.Now().Format("15:04:05"), Yellow.Regular("]"), string(bytes))
	}
	return 0, nil
}
683312
func (w *Writer) Write(buf []byte) (int, error) {
	if len(buf) > 0 {
		if w.start == -1 {
			// Find start of message index
			for i, c := range buf {
				if c == Delimiter && i > 0 {
					l := buf[i-1]
					level := Levels[l]
					if level > 0 {
						w.start = i - 1
						break
					}
				}
			}
			if w.start == -1 {
				buf = append(invalidMSG, buf...)
				return w.w.Write(buf)
			}
		}
		l := Levels[buf[w.start]]
		if l >= LogLevel() {
			return w.w.Write(buf)
		} else if l == 0 {
			buf = append(invalidMSG, buf...)
			return w.w.Write(buf)
		}
	}
	return 0, nil
}
663665
func (m *MozLogger) Write(l []byte) (int, error) {
	log := NewAppLog(m.LoggerName, l)

	out, err := log.ToJSON()
	if err != nil {
		// Need someway to notify that this happened.
		fmt.Fprintln(os.Stderr, err)
		return 0, err
	}

	_, err = m.Output.Write(append(out, '\n'))
	return len(l), err
}
1069055
func (w *DecodedJSONMessageWriter) Write(b []byte) (int, error) {
	err := jsonmessage.DisplayJSONMessagesStream(bytes.NewReader(b), w.w, w.fd, false, nil)
	if err != nil {
		if err, ok := err.(*jsonmessage.JSONError); ok {
			w.err = err
			return len(b), nil
		}
	}
	return len(b), err
}
1247541
func (rl *respLogger) Write(b []byte) (int, error) {
	if !rl.statusRecorded {
		rl.recordStatus(http.StatusOK) // Default if WriteHeader hasn't been called
	}
	if rl.captureErrorOutput {
		rl.Addf("logging error output: %q\n", string(b))
	}
	return rl.w.Write(b)
}
315148
func (w *Writer) Write(buf []byte) (n int, err error) {
	w.mtx.Lock()
	defer w.mtx.Unlock()
	return w.buf.Write(buf)
}
32292
func (w *Writer) Write(buffer []byte) (n int, err error) {
	oldCount := w.count

	n = len(buffer)
	w.count += int64(n)

	if w.onWrite != nil {
		w.onWrite(w.count)
	}

	if w.writer != nil {
		n, err = w.writer.Write(buffer)
		w.count = oldCount + int64(n)
	}

	return
}
65082
func (lg logLogger) Write(message []byte) (int, error) {
	length := len(message)
	if length > 0 {
		lg.logger.Output(2, string(message))
	}
	return length, nil
}