// Format formats according to a format specifier and returns the resulting
// string. The receiver's string representation is the first argument.
326257
func (id EventID) Format(s string, args ...interface{}) string {
	args = append([]interface{}{id.String()}, args...)
	return fmt.Sprintf(s, args...)
}
1018128
func (jf *JSONFormatter) Format(writer io.Writer, level int, msg string, args []interface{}) {
	buf := pool.Get()
	defer pool.Put(buf)

	const lead = `", "`
	const colon = `":"`

	buf.WriteString(`{"`)
	buf.WriteString(KeyMap.Time)
	buf.WriteString(`":"`)
	buf.WriteString(time.Now().Format(timeFormat))

	buf.WriteString(`", "`)
	buf.WriteString(KeyMap.PID)
	buf.WriteString(`":"`)
	buf.WriteString(pidStr)

	buf.WriteString(`", "`)
	buf.WriteString(KeyMap.Level)
	buf.WriteString(`":"`)
	buf.WriteString(LevelMap[level])

	buf.WriteString(`", "`)
	buf.WriteString(KeyMap.Name)
	buf.WriteString(`":"`)
	buf.WriteString(jf.name)

	buf.WriteString(`", "`)
	buf.WriteString(KeyMap.Message)
	buf.WriteString(`":`)
	jf.appendValue(buf, msg)

	var lenArgs = len(args)
	if lenArgs > 0 {
		if lenArgs == 1 {
			jf.set(buf, singleArgKey, args[0])
		} else if lenArgs%2 == 0 {
			for i := 0; i < lenArgs; i += 2 {
				if key, ok := args[i].(string); ok {
					if key == "" {
						// show key is invalid
						jf.set(buf, badKeyAtIndex(i), args[i+1])
					} else {
						jf.set(buf, key, args[i+1])
					}
				} else {
					// show key is invalid
					jf.set(buf, badKeyAtIndex(i), args[i+1])
				}
			}
		} else {
			jf.set(buf, warnImbalancedKey, args)
		}
	}
	buf.WriteString("}\n")
	buf.WriteTo(writer)
}
1333982
func (t *ConsoleFormatter) Format(errin error) (errtext string, err error) {
	return t.FormatSkip(errin, 1)
}
53338
func (v Variant) format() (string, bool) {
	switch v.sig.str[0] {
	case 'b', 'i':
		return fmt.Sprint(v.value), true
	case 'n', 'q', 'u', 'x', 't', 'd', 'h':
		return fmt.Sprint(v.value), false
	case 's':
		return strconv.Quote(v.value.(string)), true
	case 'o':
		return strconv.Quote(string(v.value.(ObjectPath))), false
	case 'g':
		return strconv.Quote(v.value.(Signature).str), false
	case 'v':
		s, unamb := v.value.(Variant).format()
		if !unamb {
			return "<@" + v.value.(Variant).sig.str + " " + s + ">", true
		}
		return "<" + s + ">", true
	case 'y':
		return fmt.Sprintf("%#x", v.value.(byte)), false
	}
	rv := reflect.ValueOf(v.value)
	switch rv.Kind() {
	case reflect.Slice:
		if rv.Len() == 0 {
			return "[]", false
		}
		unamb := true
		buf := bytes.NewBuffer([]byte("["))
		for i := 0; i < rv.Len(); i++ {
			// TODO: slooow
			s, b := MakeVariant(rv.Index(i).Interface()).format()
			unamb = unamb && b
			buf.WriteString(s)
			if i != rv.Len()-1 {
				buf.WriteString(", ")
			}
		}
		buf.WriteByte(']')
		return buf.String(), unamb
	case reflect.Map:
		if rv.Len() == 0 {
			return "{}", false
		}
		unamb := true
		var buf bytes.Buffer
		kvs := make([]string, rv.Len())
		for i, k := range rv.MapKeys() {
			s, b := MakeVariant(k.Interface()).format()
			unamb = unamb && b
			buf.Reset()
			buf.WriteString(s)
			buf.WriteString(": ")
			s, b = MakeVariant(rv.MapIndex(k).Interface()).format()
			unamb = unamb && b
			buf.WriteString(s)
			kvs[i] = buf.String()
		}
		buf.Reset()
		buf.WriteByte('{')
		sort.Strings(kvs)
		for i, kv := range kvs {
			if i > 0 {
				buf.WriteString(", ")
			}
			buf.WriteString(kv)
		}
		buf.WriteByte('}')
		return buf.String(), unamb
	}
	return `"INVALID"`, true
}
914237
func (f *formatState) Format(fs fmt.State, verb rune) {
	f.fs = fs

	// Use standard formatting for verbs that are not v.
	if verb != 'v' {
		format := f.constructOrigFormat(verb)
		fmt.Fprintf(fs, format, f.value)
		return
	}

	if f.value == nil {
		if fs.Flag('#') {
			fs.Write(interfaceBytes)
		}
		fs.Write(nilAngleBytes)
		return
	}

	f.format(reflect.ValueOf(f.value))
}
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()
}
739962
func (b *BasicFormatter) Format(d diff.Diff) ([]byte, error) {
	// calling jsonDiff.Format(d) populates the JSON diff's "Lines" value,
	// which we use to compute the basic dif
	_, err := b.jsonDiff.Format(d)
	if err != nil {
		return nil, err
	}

	bd := &BasicDiff{}
	blocks := bd.Basic(b.jsonDiff.Lines)
	buf := &bytes.Buffer{}

	err = b.tpl.ExecuteTemplate(buf, "block", blocks)
	if err != nil {
		return nil, err
	}
	return buf.Bytes(), nil
}
839024
func (g *Generator) Format() ([]byte, error) {
	src, err := format.Source(g.Buf.Bytes())
	if err != nil {
		return g.Buf.Bytes(), err
	}

	return src, nil
}
1187911
func (a *SerialDiffAggregation) Format(format string) *SerialDiffAggregation {
	a.format = format
	return a
}
433607
func (sf *StdFormatter) Format(e *Entry) ([]byte, error) {

	// Initialize if not set
	if sf.HeaderColor == nil {
		sf.mu.Lock()
		sf.HeaderColor = colorLabels
		sf.mu.Unlock()
	}

	// Initialize if not set
	if sf.HeaderPlain == nil {
		sf.mu.Lock()
		sf.HeaderPlain = plainLabels
		sf.mu.Unlock()
	}

	// Normal headers.  time, file, etc
	var header, message []byte
	sf.stdHeader(&header, e.Time, e.Prefix, e.File, e.Line)

	// Level headers
	headers := sf.levelHeaders()
	message = append(headers[e.Level], append(header, e.Message...)...)

	if e.Fields != nil {
		sf.stdFields(&message, e.Fields, e.Level)
	}

	return append(message, '\n'), nil
}
803975
func Format(format string, t time.Time) (result string, err error) {
	defer func() {
		if e := recover(); e != nil {
			result = ""
			err = e.(error)
		}
	}()

	fn := func(match string) string {
		return repl(match, t)
	}
	return fmtRe.ReplaceAllStringFunc(format, fn), nil
}
1016933
func (f *defaultFormatter) Format(rec *Record) string {
	return fmt.Sprintf("%s [%s] %-8s %s", fmt.Sprint(rec.Time)[:19], rec.LoggerName, LevelNames[rec.Level], fmt.Sprintf(rec.Format, rec.Args...))
}
1014257
func (a *DerivativeAggregation) Format(format string) *DerivativeAggregation {
	a.format = format
	return a
}
222185
func (s ShortFuncFormatter) Format(w io.Writer, entry zapcore.Entry, fields []zapcore.Field) {
	f := runtime.FuncForPC(entry.Caller.PC)
	if f == nil {
		fmt.Fprintf(w, s.FormatVerb, "(unknown)")
		return
	}

	fname := f.Name()
	funcIdx := strings.LastIndex(fname, ".")
	fmt.Fprintf(w, s.FormatVerb, fname[funcIdx+1:])
}
1084550
func (r *Resp) Format(s fmt.State, verb rune) {
	if r == nil || r.req == nil {
		return
	}
	if s.Flag('+') { // include header and format pretty.
		fmt.Fprint(s, r.Dump())
	} else if s.Flag('-') { // keep all informations in one line.
		r.miniFormat(s)
	} else { // auto
		r.autoFormat(s)
	}
}
874183
func (a *BucketSelectorAggregation) Format(format string) *BucketSelectorAggregation {
	a.format = format
	return a
}
27536
func (f JSONFormat) Format(buf []byte, l *Logger, t time.Time, severity int,
	msg string, fields map[string]interface{}) ([]byte, error) {
	var err error

	// assume enough capacity for mandatory fields (except for msg).
	buf = append(buf, `{"topic":"`...)
	buf = append(buf, l.Topic()...)
	buf = append(buf, `","logged_at":"`...)
	buf = t.UTC().AppendFormat(buf, RFC3339Micro)
	buf = append(buf, `","severity":`...)
	if ss, ok := severityMap[severity]; ok {
		buf = append(buf, '"')
		buf = append(buf, ss...)
		buf = append(buf, '"')
	} else {
		buf = strconv.AppendInt(buf, int64(severity), 10)
	}
	buf = append(buf, `,"utsname":"`...)
	if len(f.Utsname) > 0 {
		buf = append(buf, f.Utsname...)
	} else {
		buf = append(buf, utsname...)
	}
	buf = append(buf, `","message":`...)
	buf, err = appendJSON(buf, msg)
	if err != nil {
		return nil, err
	}

	for k, v := range fields {
		if !IsValidKey(k) {
			return nil, ErrInvalidKey
		}

		if cap(buf) < (len(k) + 4) {
			return nil, ErrTooLarge
		}
		buf = append(buf, `,"`...)
		buf = append(buf, k...)
		buf = append(buf, `":`...)
		buf, err = appendJSON(buf, v)
		if err != nil {
			return nil, err
		}
	}

	for k, v := range l.Defaults() {
		if _, ok := fields[k]; ok {
			continue
		}

		if cap(buf) < (len(k) + 4) {
			return nil, ErrTooLarge
		}
		buf = append(buf, `,"`...)
		buf = append(buf, k...)
		buf = append(buf, `":`...)
		buf, err = appendJSON(buf, v)
		if err != nil {
			return nil, err
		}
	}

	if cap(buf) < 2 {
		return nil, ErrTooLarge
	}
	return append(buf, "}\n"...), nil
}