MCPcopy
hub / github.com/uber-go/zap / TestAddCaller

Function TestAddCaller

exp/zapslog/handler_test.go:41–56  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

39)
40
41func TestAddCaller(t *testing.T) {
42 t.Parallel()
43
44 fac, logs := observer.New(zapcore.DebugLevel)
45 sl := slog.New(NewHandler(fac, WithCaller(true)))
46 sl.Info("msg")
47
48 require.Len(t, logs.AllUntimed(), 1, "Expected exactly one entry to be logged")
49 entry := logs.AllUntimed()[0]
50 assert.Equal(t, "msg", entry.Message, "Unexpected message")
51 assert.Regexp(t,
52 `/handler_test.go:\d+$`,
53 entry.Caller.String(),
54 "Unexpected caller annotation.",
55 )
56}
57
58func TestAddStack(t *testing.T) {
59 fac, logs := observer.New(zapcore.DebugLevel)

Callers

nothing calls this directly

Calls 7

NewFunction · 0.92
NewHandlerFunction · 0.85
AllUntimedMethod · 0.80
WithCallerFunction · 0.70
InfoMethod · 0.45
LenMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected