Skip to content

Commit

Permalink
Release v1.18.1, fix panic
Browse files Browse the repository at this point in the history
This releases a fix for the NopLogger breakage accidentally introduced
in v1.18.0.
  • Loading branch information
abhinav authored Jun 28, 2021
2 parents 35f15d1 + a779980 commit 120b08c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 1.18.1 (28 Jun 2021)

Bugfixes:
* [#974][]: Fix nil dereference in logger constructed by `zap.NewNop`.

[#974]: https://github.com/uber-go/zap/pull/974

## 1.18.0 (28 Jun 2021)

Enhancements:
Expand Down
1 change: 1 addition & 0 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func NewNop() *Logger {
core: zapcore.NewNopCore(),
errorOutput: zapcore.AddSync(ioutil.Discard),
addStack: zapcore.FatalLevel + 1,
clock: zapcore.DefaultClock,
}
}

Expand Down
22 changes: 21 additions & 1 deletion logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,6 @@ func TestLoggerCustomOnFatal(t *testing.T) {
for _, tt := range tests {
t.Run(tt.msg, func(t *testing.T) {
withLogger(t, InfoLevel, opts(OnFatal(tt.onFatal)), func(logger *Logger, logs *observer.ObservedLogs) {

var finished bool
recovered := make(chan interface{})
go func() {
Expand All @@ -580,6 +579,27 @@ func TestLoggerCustomOnFatal(t *testing.T) {
}
}

func TestNopLogger(t *testing.T) {
logger := NewNop()

t.Run("basic levels", func(t *testing.T) {
logger.Debug("foo", String("k", "v"))
logger.Info("bar", Int("x", 42))
logger.Warn("baz", Strings("ks", []string{"a", "b"}))
logger.Error("qux", Error(errors.New("great sadness")))
})

t.Run("DPanic", func(t *testing.T) {
logger.With(String("component", "whatever")).DPanic("stuff")
})

t.Run("Panic", func(t *testing.T) {
assert.Panics(t, func() {
logger.Panic("great sadness")
}, "Nop logger should still cause panics.")
})
}

func infoLog(logger *Logger, msg string, fields ...Field) {
logger.Info(msg, fields...)
}
Expand Down

0 comments on commit 120b08c

Please sign in to comment.