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

Function ExampleWith

log/log_example_test.go:173–181  ·  view source on GitHub ↗

Example of using the With function to add context fields

()

Source from the content-addressed store, hash-verified

171
172// Example of using the With function to add context fields
173func ExampleWith() {
174 setup()
175
176 // you have to assign the result of With() to a new Logger and can't inline the level calls
177 // because they need a *Logger receiver
178 augmented := log.With().Str("service", "myservice").Logger()
179 augmented.Info().Msg("hello world")
180 // Output: {"level":"info","service":"myservice","time":1199811905,"message":"hello world"}
181}
182
183// Example of using the Level function to set the log level
184func ExampleLevel() {

Callers

nothing calls this directly

Calls 6

WithFunction · 0.92
setupFunction · 0.85
LoggerMethod · 0.80
MsgMethod · 0.80
InfoMethod · 0.65
StrMethod · 0.45

Tested by

no test coverage detected