MCPcopy
hub / github.com/rs/zerolog / ExampleNewConsoleWriter_customFormatters

Function ExampleNewConsoleWriter_customFormatters

console_test.go:72–87  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

70}
71
72func ExampleNewConsoleWriter_customFormatters() {
73 out := zerolog.NewConsoleWriter(
74 func(w *zerolog.ConsoleWriter) {
75 // Customize time format
76 w.TimeFormat = time.RFC822
77 // Customize level formatting
78 w.FormatLevel = func(i interface{}) string { return strings.ToUpper(fmt.Sprintf("[%-5s]", i)) }
79 },
80 )
81 out.NoColor = true // For testing purposes only
82
83 log := zerolog.New(out)
84
85 log.Info().Str("foo", "bar").Msg("Hello World")
86 // Output: <nil> [INFO ] Hello World foo=bar
87}
88
89func TestConsoleLogger(t *testing.T) {
90 t.Run("Numbers", func(t *testing.T) {

Callers

nothing calls this directly

Calls 5

NewConsoleWriterFunction · 0.92
NewFunction · 0.92
MsgMethod · 0.80
InfoMethod · 0.65
StrMethod · 0.45

Tested by

no test coverage detected