From 7f757e8576de05a85554854385f14fae3143ceb4 Mon Sep 17 00:00:00 2001 From: Colin Date: Fri, 1 Mar 2024 19:22:13 +0800 Subject: [PATCH] handle level parameters Signed-off-by: Colin --- client/pkg/logutil/zap.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/client/pkg/logutil/zap.go b/client/pkg/logutil/zap.go index b839ee2a5ff..8cc68f32ebe 100644 --- a/client/pkg/logutil/zap.go +++ b/client/pkg/logutil/zap.go @@ -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 }) @@ -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, ),