shared/log15/format.go
func TerminalFormat() Format {
	return FormatFunc(func(r *Record) []byte {
		var color = 0
		switch r.Lvl {
		case LvlCrit:
			color = 35
		case LvlError:
			color = 31
		case LvlWarn:
			color = 33
		case LvlInfo:
			color = 32
		case LvlDebug:
			color = 36
		}

		b := &bytes.Buffer{}
		lvl := strings.ToUpper(r.Lvl.String())
		if color > 0 {
			fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%s] %s ", color, lvl, r.Time.Format(termTimeFormat), r.Msg)
		} else {
			fmt.Fprintf(b, "[%s] [%s] %s ", lvl, r.Time.Format(termTimeFormat), r.Msg)
		}

		// try to justify the log output for short messages
		if len(r.Ctx) > 0 && len(r.Msg) < termMsgJust {
			b.Write(bytes.Repeat([]byte{' '}, termMsgJust-len(r.Msg)))
		}

		// print the keys logfmt style
		logfmt(b, r.Ctx, color)
		return b.Bytes()
	})
}
func TerminalFormat() Format {
	return FormatFunc(func(r *Record) []byte {
		var color = 0
		switch r.Lvl {
		case LvlCrit:
			color = 35
		case LvlError:
			color = 31
		case LvlWarn:
			color = 33
		case LvlInfo:
			color = 32
		case LvlDebug:
			color = 36
		}

		b := &bytes.Buffer{}
		lvl := strings.ToUpper(r.Lvl.String())
		if color > 0 {
			fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%s] %s ", color, lvl, r.Time.Format(termTimeFormat), r.Msg)
		} else {
			fmt.Fprintf(b, "[%s] [%s] %s ", lvl, r.Time.Format(termTimeFormat), r.Msg)
		}

		// try to justify the log output for short messages
		if len(r.Ctx) > 0 && len(r.Msg) < termMsgJust {
			b.Write(bytes.Repeat([]byte{' '}, termMsgJust-len(r.Msg)))
		}

		// print the keys logfmt style
		logfmt(b, r.Ctx, color)
		return b.Bytes()
	})
}
func TerminalFormat ( ) Format { return FormatFunc ( func ( r * Record ) [ ] byte { var color = 0 switch r . Lvl { case LvlCrit : color = 35 case LvlError : color = 31 case LvlWarn : color = 33 case LvlInfo : color = 32 case LvlDebug : color = 36 } b := & bytes . Buffer { } lvl := strings . ToUpper ( r . Lvl . String ( ) ) if color > 0 { fmt . Fprintf ( b , " \x1b \x1b " , color , lvl , r . Time . Format ( termTimeFormat ) , r . Msg ) } else { fmt . Fprintf ( b , " " , lvl , r . Time . Format ( termTimeFormat ) , r . Msg ) } // try to justify the log output for short messages if len ( r . Ctx ) > 0 && len ( r . Msg ) < termMsgJust { b . Write ( bytes . Repeat ( [ ] byte { ' ' } , termMsgJust - len ( r . Msg ) ) ) } // print the keys logfmt style logfmt ( b , r . Ctx , color ) return b . Bytes ( ) } ) }
// TerminalFormat formats log records optimized for human readability on
// a terminal with color-coded level output and terser human friendly timestamp.
// This format should only be used for interactive programs or while developing.
//
//     [TIME] [LEVEL] MESAGE key=value key=value ...
//
// Example:
//
//     [May 16 20:58:45] [DBUG] remove route ns=haproxy addr=127.0.0.1:50002
//
TerminalFormat formats log records optimized for human readability on a terminal with color - coded level output and terser human friendly timestamp . This format should only be used for interactive programs or while developing . [ TIME ] [ LEVEL ] MESAGE key = value key = value ... Example : [ May 16 20 : 58 : 45 ] [ DBUG ] remove route ns = haproxy addr = 127 . 0 . 0 . 1 : 50002