Skip to content

Commit

Permalink
CheckedEntry: avoid using deprecated Should internally (#1117)
Browse files Browse the repository at this point in the history
CheckedEntry.Should was deprecated in favor of CheckedEntry.After.
  • Loading branch information
Craig Pastro committed Jun 17, 2022
1 parent c58bc94 commit 2e615d8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions logger.go
Expand Up @@ -298,7 +298,7 @@ func (log *Logger) check(lvl zapcore.Level, msg string) *zapcore.CheckedEntry {
// Set up any required terminal behavior.
switch ent.Level {
case zapcore.PanicLevel:
ce = ce.Should(ent, zapcore.WriteThenPanic)
ce = ce.After(ent, zapcore.WriteThenPanic)
case zapcore.FatalLevel:
onFatal := log.onFatal
// nil or WriteThenNoop will lead to continued execution after
Expand All @@ -318,7 +318,7 @@ func (log *Logger) check(lvl zapcore.Level, msg string) *zapcore.CheckedEntry {
ce = ce.After(ent, onFatal)
case zapcore.DPanicLevel:
if log.development {
ce = ce.Should(ent, zapcore.WriteThenPanic)
ce = ce.After(ent, zapcore.WriteThenPanic)
}
}

Expand Down
2 changes: 1 addition & 1 deletion zapcore/entry.go
Expand Up @@ -206,7 +206,7 @@ var _ CheckWriteHook = CheckWriteAction(0)
// CheckedEntry is an Entry together with a collection of Cores that have
// already agreed to log it.
//
// CheckedEntry references should be created by calling AddCore or Should on a
// CheckedEntry references should be created by calling AddCore or After on a
// nil *CheckedEntry. References are returned to a pool after Write, and MUST
// NOT be retained after calling their Write method.
type CheckedEntry struct {
Expand Down
6 changes: 3 additions & 3 deletions zapcore/entry_test.go
Expand Up @@ -111,19 +111,19 @@ func TestCheckedEntryWrite(t *testing.T) {

t.Run("WriteThenPanic", func(t *testing.T) {
var ce *CheckedEntry
ce = ce.Should(Entry{}, WriteThenPanic)
ce = ce.After(Entry{}, WriteThenPanic)
assert.Panics(t, func() { ce.Write() }, "Expected to panic when WriteThenPanic is set.")
})

t.Run("WriteThenGoexit", func(t *testing.T) {
var ce *CheckedEntry
ce = ce.Should(Entry{}, WriteThenGoexit)
ce = ce.After(Entry{}, WriteThenGoexit)
assertGoexit(t, func() { ce.Write() })
})

t.Run("WriteThenFatal", func(t *testing.T) {
var ce *CheckedEntry
ce = ce.Should(Entry{}, WriteThenFatal)
ce = ce.After(Entry{}, WriteThenFatal)
stub := exit.WithStub(func() {
ce.Write()
})
Expand Down

0 comments on commit 2e615d8

Please sign in to comment.