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 11, 2021
1 parent fbef837 commit 479d001
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
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
13 changes: 11 additions & 2 deletions 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 @@ -88,8 +89,7 @@ func main() {
flag.CommandLine.Set("zap-devel", "true")
}

logger := zap.New(zap.UseFlagOptions(&opt))
ctrl.SetLogger(logger)
setupLogger(opt)

// Lock only for handler, we can run old and new version of
// webhook without problems, policy status will be updated
Expand Down Expand Up @@ -264,6 +264,15 @@ func main() {
}
}

func setupLogger(opts zap.Options) {
opts.EncoderConfigOptions = append(opts.EncoderConfigOptions, func(ec *zapcore.EncoderConfig) {
ec.EncodeTime = zapcore.ISO8601TimeEncoder
})

logger := zap.New(zap.UseFlagOptions(&opts))
ctrl.SetLogger(logger)
}

// Start profiler on given port if ENABLE_PROFILER is True
func setProfiler() {
cfg := ProfilerConfig{}
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 479d001

Please sign in to comment.