// Copy log starting from l.Start to the given io.Writer
// Returns on error or when end of log is reached.
495274
func (l *DiagnosticLog) Copy(ctx context.Context, w io.Writer) (int, error) {
	const max = 500 // VC max == 500, ESX max == 1000
	written := 0

	for {
		h, err := l.m.BrowseLog(ctx, l.Host, l.Key, l.Start, max)
		if err != nil {
			return 0, err
		}

		for _, line := range h.LineText {
			n, err := fmt.Fprintln(w, line)
			written += n
			if err != nil {
				return written, err
			}
		}

		l.Start += int32(len(h.LineText))

		if l.Start >= h.LineEnd {
			break
		}
	}

	return written, nil
}
159008
func (s *migrationLoggingStrategy) WriteLog(m params.LogRecord) error {
	level, _ := loggo.ParseLevel(m.Level)
	var entity names.Tag
	if m.Entity != "" {
		var err error
		entity, err = names.ParseTag(m.Entity)
		if err != nil {
			return errors.Annotate(err, "parsing entity from log record")
		}
	}
	err := s.dblogger.Log([]state.LogRecord{{
		Time:     m.Time,
		Entity:   entity,
		Module:   m.Module,
		Location: m.Location,
		Level:    level,
		Message:  m.Message,
	}})
	if err == nil {
		err = s.tracker.Track(m.Time)
	}
	return errors.Annotate(err, "logging to DB failed")
}
531563
func (l *Logger) Log(format string, args ...interface{}) {
	l.log(1, false, format, args...)
}
1374502
func Log(a ...interface{}) {
	format := ""

	for range a {
		format += "%v "
	}

	format = format[:len(format)-1]
	Logger(format, a...)
}
128130
func (l *Context) Log(keyvals ...interface{}) {
	// Note: The assumption here is that copyIfDynamic is "slow" since dynamic values
	//       could be slow to calculate.  So to optimize the case of "logs are turned off"
	//       we enable the ability to early return if the logger is off.
	if l == nil || IsDisabled(l.Logger) {
		return
	}
	l.Logger.Log(copyIfDynamic(addArrays(l.KeyVals, keyvals))...)
}
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
}
1185902
func (ks *KeyServerLocal) CopyWithConfigAndLogger(
	config KeyServerConfig, log logger.Logger) *KeyServerLocal {
	return &KeyServerLocal{
		config, ks.db, log, ks.shutdownLock, ks.shutdown, ks.shutdownFunc}
}
1042636
func (l *Logger) Write(p []byte) (int, error) {
	return l.iwrite(p, l.app)
}
618174
func (writer *baseFileWriter) write(level LevelType, args ...interface{}) {
	writer.lock.RLock()
	defer writer.lock.RUnlock()
	var size = 0

	if writer.closed {
		return
	}

	size = writer.blog.write(level, args...)

	// logrotate
	if writer.sizeRotated || writer.lineRotated {
		writer.logSizeChan <- size
	}

	if nil != writer.hook && !(level < writer.hookLevel) {
		if writer.hookAsync {
			// 异步调用log hook
			go writer.hook.Fire(level, writer.blog.Tags(), args...)
		} else {
			writer.hook.Fire(level, writer.blog.Tags(), args...)
		}
	}
}
320334
func (mlf *MockLogFile) Write(contents []byte) {
	mlf.mu.Lock()
	defer mlf.mu.Unlock()

	mlf.logBuffer = append(mlf.logBuffer, contents...)
}
940416
func (log logNull) Write(message []byte) (int, error) {
	return len(message), nil
}
28412
func (w *logWriter) write(msg *logMessage) error {
	if msg.timestamp.Before(w.opts.since) {
		// Skip the line because it's older than since
		return nil
	}
	line := msg.log
	if w.opts.timestamp {
		prefix := append([]byte(msg.timestamp.Format(timeFormat)), delimiter[0])
		line = append(prefix, line...)
	}
	// If the line is longer than the remaining bytes, cut it.
	if int64(len(line)) > w.remain {
		line = line[:w.remain]
	}
	// Get the proper stream to write to.
	var stream io.Writer
	switch msg.stream {
	case runtimeapi.Stdout:
		stream = w.stdout
	case runtimeapi.Stderr:
		stream = w.stderr
	default:
		return fmt.Errorf("unexpected stream type %q", msg.stream)
	}
	n, err := stream.Write(line)
	w.remain -= int64(n)
	if err != nil {
		return err
	}
	// If the line has not been fully written, return errShortWrite
	if n < len(line) {
		return errShortWrite
	}
	// If there are no more bytes left, return errMaximumWrite
	if w.remain <= 0 {
		return errMaximumWrite
	}
	return nil
}
1174932
func (r *Writer) Write(b []byte) (int, error) {
	nl := ""
	if len(b) == 0 || b[len(b)-1] != '\n' {
		nl = "\n"
	}

	r.conn.SetWriteDeadline(time.Now().Add(1 * time.Second))

	_, err := fmt.Fprintf(r.conn, "  %s  %s%s", syslogHeader, b, nl)
	if err != nil {
		return 0, err
	}

	return len(b), nil
}
1105770
func (l Logger) Output(w io.Writer) Logger {
	l2 := New(w)
	l2.level = l.level
	l2.sampler = l.sampler
	if len(l.hooks) > 0 {
		l2.hooks = append(l2.hooks, l.hooks...)
	}
	if l.context != nil {
		l2.context = make([]byte, len(l.context), cap(l.context))
		copy(l2.context, l.context)
	}
	return l2
}
1252166
func (l *Log) Start() <-chan *Event {
	ch := make(chan *Event)
	go l.start(ch)
	return ch
}
587715
func copyEntry(e *logrus.Entry, fields logrus.Fields) *logrus.Entry {
	ne := entryPool.Get().(*logrus.Entry)
	ne.Message = e.Message
	ne.Level = e.Level
	ne.Time = e.Time
	ne.Data = logrus.Fields{}
	for k, v := range fields {
		ne.Data[k] = v
	}
	for k, v := range e.Data {
		ne.Data[k] = v
	}
	return ne
}
1205331
func writeLog(writer io.Writer, params LogFormatterParams) {
	buf := buildCommonLogLine(params.Request, params.URL, params.TimeStamp, params.StatusCode, params.Size)
	buf = append(buf, '\n')
	writer.Write(buf)
}