// Format implemented logging.Messager interface.
487733
func (err Error) Format() (string, error) {
	errlog := errorForLog{err.Code, err.Err, err.Msg, err.Data, err.Stack}
	res, e := json.Marshal(errlog)
	if e == nil {
		return string(res), nil
	}
	return "", e
}
1220927
func (cf *colorizingFormatter) Format(entry *logrus.Entry) ([]byte, error) {
	data := make(logrus.Fields, len(entry.Data)+3)
	for k, v := range entry.Data {
		switch v := v.(type) {
		case error:
			// Otherwise errors are ignored by `encoding/json`
			// https://github.com/sirupsen/logrus/issues/137
			data[k] = v.Error()
		default:
			data[k] = v
		}
	}
	timestampFormat := cf.TimestampFormat
	if timestampFormat == "" {
		timestampFormat = time.RFC3339
	}
	if !cf.DisableTimestamp {
		data[logrus.FieldKeyTime] = entry.Time.Format(timestampFormat)
	}
	data[logrus.FieldKeyMsg] = entry.Message
	data[logrus.FieldKeyLevel] = entry.Level.String()
	prettyString, prettyStringErr := prettyjson.Marshal(data)
	if prettyStringErr != nil {
		return nil, errors.Wrapf(prettyStringErr, "Failed to marshal fields to JSON")
	}
	return append(prettyString, '\n'), nil
}
662549
func (a *CumulativeSumAggregation) Format(format string) *CumulativeSumAggregation {
	a.format = format
	return a
}
179713
func (m MsgPack) Format(b []byte, l *Logger, t time.Time, severity int, msg string,
	fields map[string]interface{}) ([]byte, error) {
	b = append(b, byte(mpFixArray+3))
	b, err := appendMsgpack(b, l.Topic())
	if err != nil {
		return nil, err
	}
	b, err = appendMsgpack(b, t.Unix())
	if err != nil {
		return nil, err
	}

	// the log record consists of these objects:
	//     logged_at, severity, utsname, message, objects in fields,
	//     and objects in l.defaults excluding conflicting keys.
	var nFields uint64
	nFields += 4
	for k := range fields {
		if !ReservedKey(k) {
			nFields++
		}
	}
	for k := range l.Defaults() {
		if ReservedKey(k) {
			continue
		}
		if _, ok := fields[k]; ok {
			continue
		}
		nFields++
	}
	if nFields > math.MaxUint16 {
		return nil, ErrTooLarge
	}

	if nFields <= 15 {
		b = append(b, byte(mpFixMap+nFields))
	} else {
		b = append(b, byte(mpMap16), 0, 0)
		binary.BigEndian.PutUint16(b[len(b)-2:], uint16(nFields))
	}

	// logged_at
	b, err = appendMsgpack(b, FnLoggedAt)
	if err != nil {
		return nil, err
	}
	b, err = appendMsgpack(b, t.UnixNano()/1000)
	if err != nil {
		return nil, err
	}

	// severity
	b, err = appendMsgpack(b, FnSeverity)
	if err != nil {
		return nil, err
	}
	b, err = appendMsgpack(b, severity)
	if err != nil {
		return nil, err
	}

	// utsname
	b, err = appendMsgpack(b, FnUtsname)
	if err != nil {
		return nil, err
	}
	if len(m.Utsname) > 0 {
		b, err = appendMsgpack(b, m.Utsname)
	} else {
		b, err = appendMsgpack(b, utsname)
	}
	if err != nil {
		return nil, err
	}

	b, err = appendMsgpack(b, FnMessage)
	if err != nil {
		return nil, err
	}
	// message
	if len(b)+len(msg) > maxLogSize {
		return nil, ErrTooLarge
	}
	b, err = appendMsgpack(b, msg)
	if err != nil {
		return nil, err
	}

	// fields
	for k, v := range fields {
		if ReservedKey(k) {
			continue
		}
		if len(b)+len(k) > maxLogSize {
			return nil, ErrTooLarge
		}
		b, err = appendMsgpack(b, k)
		if err != nil {
			return nil, err
		}

		b, err = appendMsgpack(b, v)
		if err != nil {
			return nil, err
		}
	}

	// defaults
	for k, v := range l.Defaults() {
		if ReservedKey(k) {
			continue
		}
		if _, ok := fields[k]; ok {
			continue
		}
		if len(b)+len(k) > maxLogSize {
			return nil, ErrTooLarge
		}
		b, err = appendMsgpack(b, k)
		if err != nil {
			return nil, err
		}

		b, err = appendMsgpack(b, v)
		if err != nil {
			return nil, err
		}
	}

	return b, nil
}
3622
func (f *flatFormatter) Format(format string, args ...interface{}) (n int, errno error) {
	return (*indentFormatter)(f).format(true, format, args...)
}
983791
func (col *ColumnDefinition) Format(buf *TrackedBuffer) {
	buf.Myprintf("%v %v", col.Name, &col.Type)
}
1187846
func (f *CommonLogFormatter) Format(entry *logrus.Entry) ([]byte, error) {
	b := &bytes.Buffer{}

	var timestamp = defaultValue
	if v, ok := entry.Data[StartUTC]; ok {
		timestamp = v.(time.Time).Format(commonLogTimeFormat)
	}

	var elapsedMillis int64
	if v, ok := entry.Data[Duration]; ok {
		elapsedMillis = v.(time.Duration).Nanoseconds() / 1000000
	}

	_, err := fmt.Fprintf(b, "%s - %s [%s] \"%s %s %s\" %v %v %s %s %v %s %s %dms\n",
		toLog(entry.Data, ClientHost, defaultValue, false),
		toLog(entry.Data, ClientUsername, defaultValue, false),
		timestamp,
		toLog(entry.Data, RequestMethod, defaultValue, false),
		toLog(entry.Data, RequestPath, defaultValue, false),
		toLog(entry.Data, RequestProtocol, defaultValue, false),
		toLog(entry.Data, OriginStatus, defaultValue, true),
		toLog(entry.Data, OriginContentSize, defaultValue, true),
		toLog(entry.Data, "request_Referer", `"-"`, true),
		toLog(entry.Data, "request_User-Agent", `"-"`, true),
		toLog(entry.Data, RequestCount, defaultValue, true),
		toLog(entry.Data, RouterName, defaultValue, true),
		toLog(entry.Data, ServiceURL, defaultValue, true),
		elapsedMillis)

	return b.Bytes(), err
}
1165035
func (node Comments) Format(buf *TrackedBuffer) {
	for _, c := range node {
		buf.Myprintf("%s ", c)
	}
}
1347188
func (f *PoliteJSONFormatter) Format(calldepth int, r *logging.Record, w io.Writer) error {
	entry := make(map[string]interface{})
	entry["id"] = r.Id
	entry["level"] = r.Level
	entry["time"] = r.Time
	entry["module"] = r.Module
	entry["message"] = r.Message()
	err := json.NewEncoder(w).Encode(entry)
	if err != nil {
		return err
	}

	w.Write([]byte{'\n'})
	return nil
}
291525
func (e Event) Format(f fmt.State, _ rune) {
	buf := bufferPool.Get().(*buffer)
	buf.b = appendEvent(buf.b[:0], e)
	f.Write(buf.b)
	bufferPool.Put(buf)
}
149057
func (m *MultiFormatter) Format(w io.Writer, entry zapcore.Entry, fields []zapcore.Field) {
	m.mutex.RLock()
	for i := range m.formatters {
		m.formatters[i].Format(w, entry, fields)
	}
	m.mutex.RUnlock()
}
886609
func (a *MovAvgAggregation) Format(format string) *MovAvgAggregation {
	a.format = format
	return a
}
780323
func (node *Use) Format(buf *TrackedBuffer) {
	if node.DBName.v != "" {
		buf.Myprintf("use %v", node.DBName)
	} else {
		buf.Myprintf("use")
	}
}
1222501
func (f *Formatter) Format(data []byte) ([]byte, error) {
	var v interface{}
	if err := json.Unmarshal(data, &v); err != nil {
		return nil, err
	}

	return []byte(f.pretty(v, 1)), nil
}
198908
func (node *When) Format(buf *TrackedBuffer) {
	buf.Myprintf("when %v then %v", node.Cond, node.Val)
}
286128
func (t *Time) Format(f fmt.State, c rune) {
	s := &state{
		State:  f,
		verb:   c,
		hrDeg:  t.Hour(),
		caller: fsTime,
		sym:    t.Sym,
	}
	t.Err = s.writeFormatted()
}
155714
func Format(src []byte) ([]byte, error) {
	node, err := parser.Parse(src)
	if err != nil {
		return nil, err
	}

	var buf bytes.Buffer
	if err := DefaultConfig.Fprint(&buf, node); err != nil {
		return nil, err
	}

	// Add trailing newline to result
	buf.WriteString("\n")
	return buf.Bytes(), nil
}