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

Function TestLoggerAtomicLevel

logger_test.go:49–86  ·  logger_test.go::TestLoggerAtomicLevel
(t *testing.T)

Source from the content-addressed store, hash-verified

47}
48
49func TestLoggerAtomicLevel(t *testing.T) {
50 // Test that the dynamic level applies to all ancestors and descendants.
51 dl := NewAtomicLevel()
52
53 withLogger(t, dl, nil, func(grandparent *Logger, _ *observer.ObservedLogs) {
54 parent := grandparent.With(Int("generation", 1))
55 child := parent.With(Int("generation", 2))
56
57 tests := []struct {
58 setLevel zapcore.Level
59 testLevel zapcore.Level
60 enabled bool
61 }{
62 {DebugLevel, DebugLevel, true},
63 {InfoLevel, DebugLevel, false},
64 {WarnLevel, PanicLevel, true},
65 }
66
67 for _, tt := range tests {
68 dl.SetLevel(tt.setLevel)
69 for _, logger := range []*Logger{grandparent, parent, child} {
70 if tt.enabled {
71 assert.NotNil(
72 t,
73 logger.Check(tt.testLevel, ""),
74 "Expected level %s to be enabled after setting level %s.", tt.testLevel, tt.setLevel,
75 )
76 } else {
77 assert.Nil(
78 t,
79 logger.Check(tt.testLevel, ""),
80 "Expected level %s to be enabled after setting level %s.", tt.testLevel, tt.setLevel,
81 )
82 }
83 }
84 }
85 })
86}
87
88func TestLoggerLevel(t *testing.T) {
89 levels := []zapcore.Level{

Callers

nothing calls this directly

Calls 6

SetLevelMethod · 0.95
NewAtomicLevelFunction · 0.85
IntFunction · 0.85
withLoggerFunction · 0.70
WithMethod · 0.65
CheckMethod · 0.65

Tested by

no test coverage detected