Skip to content

Commit

Permalink
Use ISO8601 format for time encoding in logging
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Stäbler <cstabler@redhat.com>
  • Loading branch information
creydr committed Oct 7, 2021
1 parent c557285 commit 0e6ffe1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ require (
github.com/spf13/pflag v1.0.5
github.com/tidwall/gjson v1.8.0
github.com/tidwall/sjson v1.1.7
go.uber.org/zap v1.17.0
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.21.1
k8s.io/apimachinery v0.21.1
Expand Down
9 changes: 8 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"os"
"time"

"go.uber.org/zap/zapcore"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -253,7 +254,13 @@ func main() {
func setupLogger() {
var logType string
pflag.StringVar(&logType, "v", "production", "Log type (debug/production).")
opts := zap.Options{}
opts := zap.Options{
EncoderConfigOptions: []zap.EncoderConfigOption{
func(ec *zapcore.EncoderConfig) {
ec.EncodeTime = zapcore.ISO8601TimeEncoder
},
},
}
opts.BindFlags(flag.CommandLine)
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.Parse()
Expand Down
1 change: 1 addition & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@ go.uber.org/atomic
# go.uber.org/multierr v1.6.0
go.uber.org/multierr
# go.uber.org/zap v1.17.0
## explicit
go.uber.org/zap
go.uber.org/zap/buffer
go.uber.org/zap/internal/bufferpool
Expand Down

0 comments on commit 0e6ffe1

Please sign in to comment.