Skip to content

Commit

Permalink
fix: zap logger double entries #14
Browse files Browse the repository at this point in the history
  • Loading branch information
vdbulcke committed Dec 20, 2022
1 parent 1523863 commit 82d7d1d
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions oidc-server/logger/zap.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,23 @@ func GetZapLogger(Debug bool) *zap.Logger {
zapConfig.EncodeTime = zapcore.ISO8601TimeEncoder
consoleEncoder := zapcore.NewJSONEncoder(zapConfig)

// First, define our level-handling logic.
errorPriority := zap.LevelEnablerFunc(func(lvl zapcore.Level) bool {
return lvl >= zapcore.ErrorLevel
})
infoPriority := zap.LevelEnablerFunc(func(lvl zapcore.Level) bool {
return lvl > zapcore.DebugLevel && lvl < zapcore.ErrorLevel
})

// default writer for logger
consoleDebugging := zapcore.Lock(os.Stdout)
consoleStdout := zapcore.Lock(os.Stdout)
consoleErrors := zapcore.Lock(os.Stderr)

// set log level to writer
core := zapcore.NewTee(
// zapcore.NewCore(consoleEncoder, consoleDebugging, zap.DebugLevel),
zapcore.NewCore(consoleEncoder, consoleDebugging, zap.InfoLevel),
zapcore.NewCore(consoleEncoder, consoleErrors, zap.WarnLevel),
zapcore.NewCore(consoleEncoder, consoleErrors, zap.ErrorLevel),
zapcore.NewCore(consoleEncoder, consoleStdout, infoPriority),
zapcore.NewCore(consoleEncoder, consoleErrors, errorPriority),
)

// add function caller and stack trace on error
Expand Down

0 comments on commit 82d7d1d

Please sign in to comment.