Skip to content

Commit

Permalink
fix: cannot call SetPrimaryCore after using a Tee logger
Browse files Browse the repository at this point in the history
Signed-off-by: Manfred Touron <[email protected]>
  • Loading branch information
moul committed Sep 16, 2021
1 parent 73fb407 commit 0ae9972
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
"os"
"strings"
"testing"

"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)

func TestGetLoggerDefault(t *testing.T) {
Expand Down Expand Up @@ -240,3 +243,18 @@ func TestCustomCore(t *testing.T) {
t.Errorf("got %q, wanted it to contain log output", buf2.String())
}
}

func TestTeeCore(t *testing.T) {
// configure to use a tee logger
tee := zap.New(zapcore.NewTee(
zap.NewNop().Core(),
zap.NewNop().Core(),
), zap.AddCaller())
SetPrimaryCore(tee.Core())
log := getLogger("test")
log.Error("scooby")

// replaces the tee logger with a simple one
SetPrimaryCore(zap.NewNop().Core())
log.Error("doo")
}

0 comments on commit 0ae9972

Please sign in to comment.