Skip to content

Commit 316a110

Browse files
committed
NewTestLogger => NewLogger; return *zap.Logger
1 parent 9c4600e commit 316a110

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

zaptest/test_logger.go zaptest/logger.go

+9-12
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,26 @@ package zaptest
2323
import (
2424
"testing"
2525

26+
"go.uber.org/zap"
2627
"go.uber.org/zap/zapcore"
2728
)
2829

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
3031
// testing.TB.
3132
//
3233
// Use this with a *testing.T or *testing.B to get logs which get printed only
3334
// 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)
3837
}
3938

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.
4241
//
4342
// Use this with a *testing.T or *testing.B to get logs which get printed only
4443
// 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(
4946
zapcore.NewConsoleEncoder(zapcore.EncoderConfig{
5047
// EncoderConfig copied from zap.NewDevelopmentEncoderConfig.
5148
// 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 {
6360
}),
6461
testingWriter{t},
6562
enab,
66-
)
63+
))
6764
}
6865

6966
// testingWriter is a WriteSyncer that writes to the given testing.TB.

zaptest/test_logger_test.go zaptest/logger_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434

3535
func TestTestLoggerIncludesDebug(t *testing.T) {
3636
ts := newTestLogSpy(t)
37-
log := zap.New(NewTestLogger(ts))
37+
log := NewLogger(ts)
3838
log.Debug("calculating")
3939
log.Info("finished calculating", zap.Int("answer", 42))
4040

@@ -46,7 +46,7 @@ func TestTestLoggerIncludesDebug(t *testing.T) {
4646

4747
func TestTestLoggerAt(t *testing.T) {
4848
ts := newTestLogSpy(t)
49-
log := zap.New(NewTestLoggerAt(ts, zap.WarnLevel))
49+
log := NewLoggerAt(ts, zap.WarnLevel)
5050

5151
log.Info("received work order")
5252
log.Debug("starting work")

0 commit comments

Comments
 (0)