@@ -23,29 +23,26 @@ package zaptest
23
23
import (
24
24
"testing"
25
25
26
+ "go.uber.org/zap"
26
27
"go.uber.org/zap/zapcore"
27
28
)
28
29
29
- // NewTestLogger builds a new Core that logs all messages to the given
30
+ // NewLogger builds a new Logger that logs all messages to the given
30
31
// testing.TB.
31
32
//
32
33
// Use this with a *testing.T or *testing.B to get logs which get printed only
33
34
// if a test fails or if you ran go test -v.
34
- //
35
- // logger := zap.New(NewTestLogger(t))
36
- func NewTestLogger (t testing.TB ) zapcore.Core {
37
- return NewTestLoggerAt (t , zapcore .DebugLevel )
35
+ func NewLogger (t testing.TB ) * zap.Logger {
36
+ return NewLoggerAt (t , zapcore .DebugLevel )
38
37
}
39
38
40
- // NewTestLoggerAt builds a new Core that logs messages to the given
41
- // testing.TB if the given LevelEnabler allows it.
39
+ // NewLoggerAt builds a new Logger that logs messages to the given testing.TB
40
+ // if the given LevelEnabler allows it.
42
41
//
43
42
// Use this with a *testing.T or *testing.B to get logs which get printed only
44
43
// if a test fails or if you ran go test -v.
45
- //
46
- // logger := zap.New(NewTestLoggerAt(t, zap.InfoLevel))
47
- func NewTestLoggerAt (t testing.TB , enab zapcore.LevelEnabler ) zapcore.Core {
48
- return zapcore .NewCore (
44
+ func NewLoggerAt (t testing.TB , enab zapcore.LevelEnabler ) * zap.Logger {
45
+ return zap .New (zapcore .NewCore (
49
46
zapcore .NewConsoleEncoder (zapcore.EncoderConfig {
50
47
// EncoderConfig copied from zap.NewDevelopmentEncoderConfig.
51
48
// Can't use it directly because that would cause a cyclic import.
@@ -63,7 +60,7 @@ func NewTestLoggerAt(t testing.TB, enab zapcore.LevelEnabler) zapcore.Core {
63
60
}),
64
61
testingWriter {t },
65
62
enab ,
66
- )
63
+ ))
67
64
}
68
65
69
66
// testingWriter is a WriteSyncer that writes to the given testing.TB.
0 commit comments