Skip to content

✨[WIP] Added changes to make console encoder configurable #467

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

Closed
wants to merge 1 commit into from
Closed
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
11 changes: 8 additions & 3 deletions pkg/log/zap/zap.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ func Logger(development bool) logr.Logger {
// to the given destination, instead of stderr. It otherwise behaves like
// ZapLogger.
func LoggerTo(destWriter io.Writer, development bool) logr.Logger {
return zapr.NewLogger(RawLoggerTo(destWriter, development))
return zapr.NewLogger(RawLoggerTo(destWriter, development, false))
}

// RawLoggerTo returns a new zap.Logger configured with KubeAwareEncoder
// which logs to a given destination
func RawLoggerTo(destWriter io.Writer, development bool, opts ...zap.Option) *zap.Logger {
func RawLoggerTo(destWriter io.Writer, development bool, consoleEncoder bool, opts ...zap.Option) *zap.Logger {
// this basically mimics New<type>Config, but with a custom sink
sink := zapcore.AddSync(destWriter)

Expand All @@ -59,7 +59,12 @@ func RawLoggerTo(destWriter io.Writer, development bool, opts ...zap.Option) *za
opts = append(opts, zap.Development(), zap.AddStacktrace(zap.ErrorLevel))
} else {
encCfg := zap.NewProductionEncoderConfig()
enc = zapcore.NewJSONEncoder(encCfg)
if consoleEncoder {
enc = zapcore.NewConsoleEncoder(encCfg)
} else {
enc = zapcore.NewJSONEncoder(encCfg)
}

lvl = zap.NewAtomicLevelAt(zap.InfoLevel)
opts = append(opts, zap.AddStacktrace(zap.WarnLevel),
zap.WrapCore(func(core zapcore.Core) zapcore.Core {
Expand Down