From 26fb0ceed2bd773509a1a398337fcdf88bca2727 Mon Sep 17 00:00:00 2001 From: albertteoh Date: Sat, 7 May 2022 20:59:38 +1000 Subject: [PATCH 1/2] Fix es.log-level Signed-off-by: albertteoh --- pkg/es/config/config.go | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/pkg/es/config/config.go b/pkg/es/config/config.go index 7fe513aa776..94d4e6767ed 100644 --- a/pkg/es/config/config.go +++ b/pkg/es/config/config.go @@ -21,6 +21,7 @@ import ( "crypto/tls" "errors" "fmt" + "go.uber.org/zap/zapcore" "net/http" "os" "path/filepath" @@ -458,26 +459,38 @@ func addLoggerOptions(options []elastic.ClientOptionFunc, logLevel string) ([]el // e.g. --log-level=info and --es.log-level=debug would mute ES's debug logging and would require --log-level=debug // to show ES debug logs. prodConfig := zap.NewProductionConfig() - prodConfig.Level.SetLevel(zap.DebugLevel) - esLogger, err := prodConfig.Build() - if err != nil { - return options, err - } + var lvl zapcore.Level + var loggerOpts []zapgrpc.Option + var setLogger func(logger elastic.Logger) elastic.ClientOptionFunc - // Elastic client requires a "Printf"-able logger. - l := zapgrpc.NewLogger(esLogger) switch logLevel { case "debug": - l = zapgrpc.NewLogger(esLogger, zapgrpc.WithDebug()) - options = append(options, elastic.SetTraceLog(l)) + lvl = zap.DebugLevel + setLogger = elastic.SetTraceLog + + // Enables the "level":"debug" log field. Without this, + // the "level" field defaults to "info". + loggerOpts = append(loggerOpts, zapgrpc.WithDebug()) case "info": - options = append(options, elastic.SetInfoLog(l)) + lvl = zap.InfoLevel + setLogger = elastic.SetInfoLog case "error": - options = append(options, elastic.SetErrorLog(l)) + lvl = zap.ErrorLevel + setLogger = elastic.SetErrorLog default: return options, fmt.Errorf("unrecognized log-level: \"%s\"", logLevel) } + + prodConfig.Level.SetLevel(lvl) + esLogger, err := prodConfig.Build() + if err != nil { + return options, err + } + + // Elastic client requires a "Printf"-able logger. + l := zapgrpc.NewLogger(esLogger, loggerOpts...) + options = append(options, setLogger(l)) return options, nil } From 39140c9b4211529d7f400b842a5bd4a988ad9d5c Mon Sep 17 00:00:00 2001 From: albertteoh Date: Sat, 7 May 2022 21:23:27 +1000 Subject: [PATCH 2/2] go imports Signed-off-by: albertteoh --- pkg/es/config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/es/config/config.go b/pkg/es/config/config.go index 94d4e6767ed..2bbdd181ed7 100644 --- a/pkg/es/config/config.go +++ b/pkg/es/config/config.go @@ -21,7 +21,6 @@ import ( "crypto/tls" "errors" "fmt" - "go.uber.org/zap/zapcore" "net/http" "os" "path/filepath" @@ -33,6 +32,7 @@ import ( "github.com/olivere/elastic" "github.com/uber/jaeger-lib/metrics" "go.uber.org/zap" + "go.uber.org/zap/zapcore" "go.uber.org/zap/zapgrpc" "github.com/jaegertracing/jaeger/pkg/bearertoken"