// Write a log line to an io.Writer.
498808
func (hook *LfsHook) ioWrite(entry *logrus.Entry) error {
	var (
		writer io.Writer
		msg    []byte
		err    error
		ok     bool
	)

	if writer, ok = hook.writers[entry.Level]; !ok {
		if hook.hasDefaultWriter {
			writer = hook.defaultWriter
		} else {
			return nil
		}
	}

	// use our formatter instead of entry.String()
	msg, err = hook.formatter.Format(entry)

	if err != nil {
		log.Println("failed to generate string for entry:", err)
		return err
	}
	_, err = writer.Write(msg)
	return err
}
228965
func (blog *BLog) write(level LevelType, args ...interface{}) int {
	blog.lock.Lock()
	defer blog.lock.Unlock()

	// 统计日志size
	var size = 0

	format := fmt.Sprintf("msg=\"%s\" ", fmt.Sprint(args...))

	blog.writer.Write(timeCache.Format())
	blog.writer.WriteString(level.prefix())
	blog.writer.WriteString(blog.tagStr)
	blog.writer.WriteString(format)
	blog.writer.WriteByte(EOL)

	size = len(timeCache.Format()) + len(level.prefix()) + len(blog.tagStr) + len(format) + 1
	return size
}
430206
func (l *LogFile) WriteString(s string) (int, error) {
	l.Lock()
	defer l.Unlock()
	return l.writer.Write([]byte(s))
}
500714
func (w *Writer) Write(data []byte) (n int, err error) {
	if w.writer == nil {
		if w.filename == "" {
			w.writer = os.Stdout
			w.filename = os.Stdout.Name()
		} else {
			file, err := os.Create(w.filename)
			if err != nil {
				return 0, err
			}
			w.writer = file
		}
	}
	return w.writer.Write(data)
}
539106
func (al *ApacheLog) WriteLog(dst io.Writer, ctx LogCtx) error {
	buf := getLogBuffer()
	defer releaseLogBuffer(buf)

	if err := al.format.WriteTo(buf, ctx); err != nil {
		return errors.Wrap(err, "failed to format log line")
	}

	b := buf.Bytes()
	if b[len(b)-1] != '\n' {
		buf.WriteByte('\n')
	}

	if _, err := buf.WriteTo(dst); err != nil {
		return errors.Wrap(err, "failed to write formated line to destination")
	}
	return nil
}
677133
func (o testOutput) Write(p []byte) (int, error) {
	msg := strings.TrimSpace(string(p))
	o.Log(msg)
	return len(p), nil
}
679755
func (b *Buffer) Write(bs []byte) (int, error) {
	if b.size < 2 {
		return b.write(bs)
	}

	// 参数 bs 来源于 log.Logger.buf，该变量会被 log.Logger 不断
	// 重复使用，所以此处应该复制一份 bs 的内容再保存。
	cp := make([]byte, 0, len(bs))
	b.buffer = append(b.buffer, append(cp, bs...))

	if len(b.buffer) < b.size {
		return len(bs), nil
	}

	return b.Flush()
}
65082
func (lg logLogger) Write(message []byte) (int, error) {
	length := len(message)
	if length > 0 {
		lg.logger.Output(2, string(message))
	}
	return length, nil
}
490051
func WriteLogs(writer io.Writer, logs []*types.Log) {
	for _, log := range logs {
		fmt.Fprintf(writer, "LOG%d: %x bn=%d txi=%x\n", len(log.Topics), log.Address, log.BlockNumber, log.TxIndex)

		for i, topic := range log.Topics {
			fmt.Fprintf(writer, "%08d  %x\n", i, topic)
		}

		fmt.Fprint(writer, hex.Dump(log.Data))
		fmt.Fprintln(writer)
	}
}
524383
func (w *LogWriter) Write(b []byte) (int, error) {
	return len(b), nil
}
376631
func (bw *BufferedFileWriter) Write(p []byte) (int, error) {
	bw.mu.Lock()
	n, err := bw.bufWriter.Write(p)

	// Special Case... if the used space in the buffer is LESS than
	// the input, then we did a flush in the middle of the line
	// and the full log line was not sent on its way.
	if bw.bufWriter.Buffered() < len(p) {
		bw.bufWriter.Flush()
	}

	bw.mu.Unlock()
	return n, err
}
320334
func (mlf *MockLogFile) Write(contents []byte) {
	mlf.mu.Lock()
	defer mlf.mu.Unlock()

	mlf.logBuffer = append(mlf.logBuffer, contents...)
}
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
}
1121039
func (w *Writer) Write(buf []byte) (int, error) {
	return w.Writer.Write(buf)
}
923594
func (l *Logger) Write(p []byte) (wLen int, err error) {
	var write = func(w io.Writer, isStdFile bool) {
		x := p
		if !isStdFile && l.flags&LnoFileAnsi != 0 {
			// TODO: If Lcolor is used, then no coloring should
			// have to be stripped. Inefficient.
			x = stripAnsiByte(x)
		}
		wLen, err = w.Write(x)
		if wLen != len(p) {
			err = io.ErrShortWrite
		}
	}
	for _, w := range l.streams {
		wIface := reflect.ValueOf(w).Interface()
		switch wType := wIface.(type) {
		case *os.File:
			if wType == os.Stdout || wType == os.Stderr {
				write(w, true)
				continue
			}
			write(w, false)
		default:
			write(w, false)
		}
	}
	return
}
278124
func (n *LevelLogger) Write(p []byte) (int, error) {
	if !n.Enabled() {
		return len(p), nil
	}
	n.Printf("%s", p)
	return len(p), nil
}
649749
func (s *Logging) Write(b []byte) (int, error) {
	s.mutex.RLock()
	w := s.writer
	s.mutex.RUnlock()

	return w.Write(b)
}