Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use JSON logger with ISO8601 time encoder for controller manager #525

Merged
merged 2 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}