Skip to content

Commit

Permalink
⚠ Zap log: Default to RFC3339 time encoding
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alvaroaleman committed Oct 21, 2022
1 parent 9f9e840 commit 60e524b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pkg/log/zap/zap.go
Expand Up @@ -168,7 +168,7 @@ type Options struct {
// underlying Zap logger.
ZapOpts []zap.Option
// TimeEncoder specifies the encoder for the timestamps in log messages.
// Defaults to EpochTimeEncoder as this is the default in Zap currently.
// Defaults to RFC3339TimeEncoder.
TimeEncoder zapcore.TimeEncoder
}

Expand Down Expand Up @@ -217,7 +217,7 @@ func (o *Options) addDefaults() {
}

if o.TimeEncoder == nil {
o.TimeEncoder = zapcore.EpochTimeEncoder
o.TimeEncoder = zapcore.RFC3339TimeEncoder
}
f := func(ecfg *zapcore.EncoderConfig) {
ecfg.EncodeTime = o.TimeEncoder
Expand Down
4 changes: 2 additions & 2 deletions pkg/log/zap/zap_test.go
Expand Up @@ -502,7 +502,7 @@ var _ = Describe("Zap log level flag options setup", func() {
Expect(optVal.Pointer()).To(Equal(expVal.Pointer()))
})

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

optVal := reflect.ValueOf(opt.TimeEncoder)
expVal := reflect.ValueOf(zapcore.EpochTimeEncoder)
expVal := reflect.ValueOf(zapcore.RFC3339TimeEncoder)

Expect(optVal.Pointer()).To(Equal(expVal.Pointer()))
})
Expand Down

0 comments on commit 60e524b

Please sign in to comment.