Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix es.log-level behaviour #3664

Merged
merged 3 commits into from
May 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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