Skip to content

Commit

Permalink
Use JSON logger with ISO8601 time encoder for controller manager (#525)
Browse files Browse the repository at this point in the history
* Use JSON logger with ISO8601 time encoder for controller manager
  • Loading branch information
shreyas-s-rao committed Feb 15, 2023
1 parent d29781f commit 56fbc66
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/golang/mock v1.6.0
github.com/onsi/ginkgo/v2 v2.1.4
github.com/onsi/gomega v1.20.0
go.uber.org/zap v1.21.0
k8s.io/api v0.25.0
k8s.io/apimachinery v0.25.0
k8s.io/client-go v11.0.1-0.20190409021438-1a26190bd76a+incompatible
Expand Down Expand Up @@ -99,7 +100,6 @@ require (
go.opencensus.io v0.23.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/crypto v0.0.0-20220516162934-403b01795ae8 // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
Expand Down
13 changes: 12 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package main

import (
"flag"
"go.uber.org/zap/zapcore"
"os"
"time"

Expand Down Expand Up @@ -86,7 +87,7 @@ func main() {

flag.Parse()

ctrl.SetLogger(zap.New(zap.UseDevMode(true)))
ctrl.SetLogger(zap.New(buildDefaultLoggerOpts()...))

ctx := ctrl.SetupSignalHandler()

Expand Down Expand Up @@ -174,3 +175,13 @@ func main() {
os.Exit(1)
}
}

func buildDefaultLoggerOpts() []zap.Opts {
var opts []zap.Opts
opts = append(opts, zap.UseDevMode(false))
opts = append(opts, zap.JSONEncoder(func(encoderConfig *zapcore.EncoderConfig) {
encoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
encoderConfig.EncodeDuration = zapcore.StringDurationEncoder
}))
return opts
}

0 comments on commit 56fbc66

Please sign in to comment.