File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -170,6 +170,11 @@ type Options struct {
170
170
// TimeEncoder specifies the encoder for the timestamps in log messages.
171
171
// Defaults to EpochTimeEncoder as this is the default in Zap currently.
172
172
TimeEncoder zapcore.TimeEncoder
173
+ // UseKubeAwareEncoder configures the logger to use the KubeAwareEncoder for encoding kubernetes
174
+ // object as Type information and Namespace/Name.
175
+ // Note: KubeAwareEncoder could NOT resolve the object passed by logger.WithValues(), see
176
+ // https://github.com/kubernetes-sigs/controller-runtime/issues/1290
177
+ UseKubeAwareEncoder bool
173
178
}
174
179
175
180
// addDefaults adds defaults to the Options.
@@ -245,7 +250,11 @@ func NewRaw(opts ...Opts) *zap.Logger {
245
250
sink := zapcore .AddSync (o .DestWriter )
246
251
247
252
o .ZapOpts = append (o .ZapOpts , zap .AddCallerSkip (1 ), zap .ErrorOutput (sink ))
248
- log := zap .New (zapcore .NewCore (& KubeAwareEncoder {Encoder : o .Encoder , Verbose : o .Development }, sink , o .Level ))
253
+ encoder := o .Encoder
254
+ if o .UseKubeAwareEncoder {
255
+ encoder = & KubeAwareEncoder {Encoder : o .Encoder , Verbose : o .Development }
256
+ }
257
+ log := zap .New (zapcore .NewCore (encoder , sink , o .Level ))
249
258
log = log .WithOptions (o .ZapOpts ... )
250
259
return log
251
260
}
You can’t perform that action at this time.
0 commit comments