From 60e524b7f4a6264662adfd1a2bd3e40b75393270 Mon Sep 17 00:00:00 2001 From: Alvaro Aleman Date: Fri, 21 Oct 2022 15:12:58 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9A=A0=20Zap=20log:=20Default=20to=20RFC3339?= =?UTF-8?q?=20time=20encoding?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- pkg/log/zap/zap.go | 4 ++-- pkg/log/zap/zap_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/log/zap/zap.go b/pkg/log/zap/zap.go index 1a27ad09b9..ee89a7c6a4 100644 --- a/pkg/log/zap/zap.go +++ b/pkg/log/zap/zap.go @@ -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 } @@ -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 diff --git a/pkg/log/zap/zap_test.go b/pkg/log/zap/zap_test.go index 748923b9f1..1a8b3995c2 100644 --- a/pkg/log/zap/zap_test.go +++ b/pkg/log/zap/zap_test.go @@ -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) @@ -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())) })