MCPcopy
hub / github.com/go-kit/kit / ExampleNewLogger_redErrors

Function ExampleNewLogger_redErrors

log/term/example_test.go:11–26  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9)
10
11func ExampleNewLogger_redErrors() {
12 // Color errors red
13 colorFn := func(keyvals ...interface{}) term.FgBgColor {
14 for i := 1; i < len(keyvals); i += 2 {
15 if _, ok := keyvals[i].(error); ok {
16 return term.FgBgColor{Fg: term.White, Bg: term.Red}
17 }
18 }
19 return term.FgBgColor{}
20 }
21
22 logger := term.NewLogger(os.Stdout, log.NewLogfmtLogger, colorFn)
23
24 logger.Log("msg", "default color", "err", nil)
25 logger.Log("msg", "colored because of error", "err", errors.New("coloring error"))
26}
27
28func ExampleNewLogger_levelColors() {
29 // Color by level value

Callers

nothing calls this directly

Calls 2

LogMethod · 0.95
NewLoggerFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…