@@ -8,10 +8,37 @@ type TestingT zerolog.TestingLog
88
99// NewTestLogger returns a logger that calls t.Log to write entries.
1010//
11+ // The returned logger emits messages at any level.
12+ // For active debugging of a test with verbose logs,
13+ // the [NewTestLoggerInfo] and [NewTestLoggerError] functions
14+ // only emit messages at or above the corresponding log levels.
15+ //
1116// If the logs may help debug a test failure,
1217// you may want to use NewTestLogger(t) in your test.
1318// Otherwise, use NewNopLogger().
1419func NewTestLogger (t TestingT ) Logger {
20+ return newTestLogger (t , zerolog .DebugLevel )
21+ }
22+
23+ // NewTestLoggerInfo returns a test logger that filters out messages
24+ // below info level.
25+ //
26+ // This is primarily helpful during active debugging of a test
27+ // with verbose logs.
28+ func NewTestLoggerInfo (t TestingT ) Logger {
29+ return newTestLogger (t , zerolog .InfoLevel )
30+ }
31+
32+ // NewTestLoggerError returns a test logger that filters out messages
33+ // below Error level.
34+ //
35+ // This is primarily helpful during active debugging of a test
36+ // with verbose logs.
37+ func NewTestLoggerError (t TestingT ) Logger {
38+ return newTestLogger (t , zerolog .ErrorLevel )
39+ }
40+
41+ func newTestLogger (t TestingT , lvl zerolog.Level ) Logger {
1542 cw := zerolog .NewConsoleWriter ()
1643 cw .Out = zerolog.TestWriter {
1744 T : t ,
@@ -22,5 +49,5 @@ func NewTestLogger(t TestingT) Logger {
2249 // but Frame=7 prints correct source locations.
2350 Frame : 7 ,
2451 }
25- return NewCustomLogger (zerolog .New (cw ))
52+ return NewCustomLogger (zerolog .New (cw ). Level ( lvl ) )
2653}
0 commit comments