Skip to content

Commit ea816ee

Browse files
committed
wip
Signed-off-by: Armando Ruocco <[email protected]>
1 parent 2b0f0e4 commit ea816ee

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

pkg/log/flags.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,17 @@ func GetFieldsRemapFlags() (res []string) {
8181
return res
8282
}
8383

84-
func (l *Flags) BuildLogger() logr.Logger {
85-
if l.zapOptions.TimeEncoder == nil {
86-
l.zapOptions.TimeEncoder = zapcore.RFC3339NanoTimeEncoder
84+
// GetOptions returns the zap options
85+
func (l *Flags) GetOptions() zap.Options {
86+
return l.zapOptions
87+
}
88+
89+
func BuildLogger(options zap.Options) logr.Logger {
90+
if options.TimeEncoder == nil {
91+
options.TimeEncoder = zapcore.RFC3339NanoTimeEncoder
8792
}
8893

89-
lgr := zap.New(zap.UseFlagOptions(&l.zapOptions), customLevel, customDestination, remapKeys)
94+
lgr := zap.New(zap.UseFlagOptions(&options), customLevel, customDestination, remapKeys)
9095
switch logLevel {
9196
case ErrorLevelString,
9297
WarningLevelString,
@@ -105,7 +110,7 @@ func (l *Flags) BuildLogger() logr.Logger {
105110
// passed from the user
106111
// This is executed after args were already parsed.
107112
func (l *Flags) ConfigureLogging() {
108-
lgr := l.BuildLogger()
113+
lgr := BuildLogger(l.zapOptions)
109114
SetGlobalLogger(lgr)
110115
}
111116

@@ -117,7 +122,8 @@ func SetGlobalLogger(lgr logr.Logger) {
117122
SetLogger(lgr)
118123
}
119124

120-
func getLogLevel(l string) zapcore.Level {
125+
// GetLogLevel returns the zap log level from a string
126+
func GetLogLevel(l string) zapcore.Level {
121127
switch l {
122128
case ErrorLevelString:
123129
return ErrorLevel
@@ -163,7 +169,7 @@ func remapKeys(in *zap.Options) {
163169
}
164170

165171
func customLevel(in *zap.Options) {
166-
in.Level = getLogLevel(logLevel)
172+
in.Level = GetLogLevel(logLevel)
167173
in.EncoderConfigOptions = append(in.EncoderConfigOptions, func(c *zapcore.EncoderConfig) {
168174
c.EncodeLevel = func(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder) {
169175
enc.AppendString(getLogLevelString(l))

0 commit comments

Comments
 (0)