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

Function ExampleCtx

log/log_example_test.go:226–234  ·  view source on GitHub ↗

Example of using the Ctx function in the log package to log with context

()

Source from the content-addressed store, hash-verified

224
225// Example of using the Ctx function in the log package to log with context
226func ExampleCtx() {
227 setup()
228
229 hooked := log.Hook(captainHook)
230 ctx := context.WithValue(context.Background(), valueKey, "12345")
231 logger := hooked.With().Ctx(ctx).Logger()
232 log.Ctx(logger.WithContext(ctx)).Info().Msg("hello world")
233 // Output: {"level":"info","time":1199811905,"key":"12345","is_error":false,"msg_len":11,"message":"hello world"}
234}
235
236// Example of using the Sample function in the log package to set a sampler
237func ExampleSample() {

Callers

nothing calls this directly

Calls 9

HookFunction · 0.92
CtxFunction · 0.92
setupFunction · 0.85
LoggerMethod · 0.80
WithMethod · 0.80
MsgMethod · 0.80
WithContextMethod · 0.80
InfoMethod · 0.65
CtxMethod · 0.45

Tested by

no test coverage detected