diff --git a/src/query/util/logging/log.go b/src/query/util/logging/log.go index d48a8cba2b..67d8a3920c 100644 --- a/src/query/util/logging/log.go +++ b/src/query/util/logging/log.go @@ -30,7 +30,7 @@ import ( xhttp "github.com/m3db/m3/src/x/net/http" - "github.com/opentracing/opentracing-go" + opentracing "github.com/opentracing/opentracing-go" "github.com/pborman/uuid" "go.uber.org/zap" "go.uber.org/zap/zapcore" @@ -45,18 +45,20 @@ const ( undefinedID = "undefined" ) -var logger *zap.Logger +var ( + logger *zap.Logger -// InitWithCores is used to set up a new logger. -func InitWithCores(cores []zapcore.Core) { - consoleEncoder := zapcore.NewConsoleEncoder(zap.NewDevelopmentEncoderConfig()) - - highPriority := zap.LevelEnablerFunc(func(lvl zapcore.Level) bool { + highPriority = zap.LevelEnablerFunc(func(lvl zapcore.Level) bool { return lvl >= zapcore.ErrorLevel }) - lowPriority := zap.LevelEnablerFunc(func(lvl zapcore.Level) bool { + lowPriority = zap.LevelEnablerFunc(func(lvl zapcore.Level) bool { return lvl < zapcore.ErrorLevel }) +) + +// InitWithCores is used to set up a new logger. +func InitWithCores(cores []zapcore.Core) { + consoleEncoder := zapcore.NewConsoleEncoder(zap.NewDevelopmentEncoderConfig()) consoleErrors := zapcore.Lock(os.Stderr) consoleDebugging := zapcore.Lock(os.Stdout) @@ -70,7 +72,7 @@ func InitWithCores(cores []zapcore.Core) { core := zapcore.NewTee(cores...) - logger = zap.New(core).WithOptions(zap.AddStacktrace(highPriority)) + logger = zap.New(core) defer logger.Sync() } @@ -162,7 +164,7 @@ func withPanicErrorResponderFunc( defer func() { if err := recover(); err != nil { - logger := WithContext(r.Context()) + logger := WithContext(r.Context()).WithOptions(zap.AddStacktrace(highPriority)) logger.Error("panic captured", zap.Any("stack", err)) if !writeCheckWriter.Written() {