Skip to content

Commit

Permalink
handle level parameters
Browse files Browse the repository at this point in the history
Signed-off-by: Colin <[email protected]>
  • Loading branch information
LLiuJJ committed Mar 1, 2024
1 parent d402b1b commit 7f757e8
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions client/pkg/logutil/zap.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ func CreateDefaultZapLogger(level zapcore.Level) (*zap.Logger, error) {

// CreateUtilZapLogger creates a logger with default zap configuration can redirect log to /dev/null
func CreateUtilZapLogger(level zapcore.Level) *zap.Logger {
lcfg := DefaultZapLoggerConfig
lcfg.Level = zap.NewAtomicLevelAt(level)
infoLevel := zap.LevelEnablerFunc(func(level zapcore.Level) bool {
return level == zapcore.InfoLevel
})
Expand All @@ -46,12 +48,12 @@ func CreateUtilZapLogger(level zapcore.Level) *zap.Logger {
stderrSyncer := zapcore.Lock(os.Stderr)
core := zapcore.NewTee(
zapcore.NewCore(
zapcore.NewJSONEncoder(DefaultZapLoggerConfig.EncoderConfig),
zapcore.NewJSONEncoder(lcfg.EncoderConfig),
stdoutSyncer,
infoLevel,
),
zapcore.NewCore(
zapcore.NewJSONEncoder(DefaultZapLoggerConfig.EncoderConfig),
zapcore.NewJSONEncoder(lcfg.EncoderConfig),
stderrSyncer,
errorFatalLevel,
),
Expand Down

0 comments on commit 7f757e8

Please sign in to comment.