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

Function ExampleContext_Objects

log_example_test.go:470–483  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

468 // Output: {"foo":"bar","user":{"name":"John","age":35,"created":"0001-01-01T00:00:00Z"},"message":"hello world"}
469}
470func ExampleContext_Objects() {
471 // User implements zerolog.LogObjectMarshaler
472 u := User{"John", 35, time.Time{}}
473 u2 := User{"Bono", 54, time.Time{}}
474
475 log := zerolog.New(os.Stdout).With().
476 Str("foo", "bar").
477 Objects("users", []zerolog.LogObjectMarshaler{u, u2}).
478 Logger()
479
480 log.Log().Msg("hello world")
481
482 // Output: {"foo":"bar","users":[{"name":"John","age":35,"created":"0001-01-01T00:00:00Z"},{"name":"Bono","age":54,"created":"0001-01-01T00:00:00Z"}],"message":"hello world"}
483}
484
485func ExampleContext_ObjectsV() {
486 // User implements zerolog.LogObjectMarshaler

Callers

nothing calls this directly

Calls 7

NewFunction · 0.92
LoggerMethod · 0.80
WithMethod · 0.80
MsgMethod · 0.80
LogMethod · 0.65
ObjectsMethod · 0.45
StrMethod · 0.45

Tested by

no test coverage detected