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

Function Test_InterfaceLogObjectMarshaler

ctx_test.go:85–102  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

83}
84
85func Test_InterfaceLogObjectMarshaler(t *testing.T) {
86 var buf bytes.Buffer
87 log := New(&buf)
88 ctx := log.WithContext(context.Background())
89
90 log2 := Ctx(ctx)
91
92 withLog := log2.With().Interface("obj", &logObjectMarshalerImpl{
93 name: "FOO",
94 age: 29,
95 }).Logger()
96
97 withLog.Info().Msg("test")
98
99 if got, want := cbor.DecodeIfBinaryToString(buf.Bytes()), `{"level":"info","obj":{"name":"foo","age":-29},"message":"test"}`+"\n"; got != want {
100 t.Errorf("got %q, want %q", got, want)
101 }
102}

Callers

nothing calls this directly

Calls 10

DecodeIfBinaryToStringFunction · 0.92
NewFunction · 0.85
WithContextMethod · 0.80
LoggerMethod · 0.80
WithMethod · 0.80
MsgMethod · 0.80
CtxFunction · 0.70
InfoMethod · 0.65
InterfaceMethod · 0.45
BytesMethod · 0.45

Tested by

no test coverage detected