Skip to content

Commit 60e524b

Browse files
committed
⚠ Zap log: Default to RFC3339 time encoding
The zap logger currently defaults to epoch time encoding which is pretty much imposisble to parse for humands. Default to RFC339 instead, as that is well-parseable by both humans and machines.
1 parent 9f9e840 commit 60e524b

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

pkg/log/zap/zap.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ type Options struct {
168168
// underlying Zap logger.
169169
ZapOpts []zap.Option
170170
// TimeEncoder specifies the encoder for the timestamps in log messages.
171-
// Defaults to EpochTimeEncoder as this is the default in Zap currently.
171+
// Defaults to RFC3339TimeEncoder.
172172
TimeEncoder zapcore.TimeEncoder
173173
}
174174

@@ -217,7 +217,7 @@ func (o *Options) addDefaults() {
217217
}
218218

219219
if o.TimeEncoder == nil {
220-
o.TimeEncoder = zapcore.EpochTimeEncoder
220+
o.TimeEncoder = zapcore.RFC3339TimeEncoder
221221
}
222222
f := func(ecfg *zapcore.EncoderConfig) {
223223
ecfg.EncodeTime = o.TimeEncoder

pkg/log/zap/zap_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ var _ = Describe("Zap log level flag options setup", func() {
502502
Expect(optVal.Pointer()).To(Equal(expVal.Pointer()))
503503
})
504504

505-
It("Should default to 'epoch' time encoding", func() {
505+
It("Should default to 'rfc3339' time encoding", func() {
506506
args := []string{""}
507507
fromFlags.BindFlags(&fs)
508508
err := fs.Parse(args)
@@ -513,7 +513,7 @@ var _ = Describe("Zap log level flag options setup", func() {
513513
opt.addDefaults()
514514

515515
optVal := reflect.ValueOf(opt.TimeEncoder)
516-
expVal := reflect.ValueOf(zapcore.EpochTimeEncoder)
516+
expVal := reflect.ValueOf(zapcore.RFC3339TimeEncoder)
517517

518518
Expect(optVal.Pointer()).To(Equal(expVal.Pointer()))
519519
})

0 commit comments

Comments
 (0)