Skip to content

Commit

Permalink
Fix es.log-level behaviour (jaegertracing#3664)
Browse files Browse the repository at this point in the history
Signed-off-by: Albert Teoh <[email protected]>
  • Loading branch information
albertteoh committed Jul 13, 2022
1 parent fa09b74 commit 58b480d
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions pkg/es/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,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"
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 58b480d

Please sign in to comment.