Skip to content

Commit a1d54b7

Browse files
Update logger to ISO8601 (#98)
Description of changes: The current logs are written in Unix nanosecond timestamp, but are awkwardly represented with scientific notation (eg. `1.6559302967712986e+09`). These timestamps are almost impossible for a human to read and because of their notation are also not suitable for log ingestion. This pull request updates the logger to use the ISO8601 standard format (eg. `2022-06-23T23:19:35.040Z`). This should make it much clearer to developers (and end users) how much time elapsed between events. ISO8601 is a standard format for timestamps that is properly supported by log ingest tools, as well. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent b9dd8fb commit a1d54b7

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

pkg/config/config.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ var (
5353
acktags.NamespaceTagFormat,
5454
),
5555
}
56+
defaultLogLevel = zapcore.InfoLevel
5657
)
5758

5859
// Config contains configuration otpions for ACK service controllers
@@ -114,7 +115,7 @@ func (cfg *Config) BindFlags() {
114115
flag.StringVar(
115116
&cfg.LogLevel, flagLogLevel,
116117
"info",
117-
"The log level. Default is info. We use logr interface which only supports info and debug level",
118+
"The log level. The default is info. The options are: debug, info, warn, error, dpanic, panic, fatal",
118119
)
119120
flag.StringSliceVar(
120121
&cfg.ResourceTags, flagResourceTags,
@@ -131,18 +132,13 @@ func (cfg *Config) BindFlags() {
131132

132133
// SetupLogger initializes the logger used in the service controller
133134
func (cfg *Config) SetupLogger() {
134-
var lvl zapcore.LevelEnabler
135-
136-
switch cfg.LogLevel {
137-
case "debug":
138-
lvl = zapcore.DebugLevel
139-
default:
140-
lvl = zapcore.InfoLevel
141-
}
135+
lvl := defaultLogLevel
136+
lvl.UnmarshalText([]byte(cfg.LogLevel))
142137

143138
zapOptions := zap.Options{
144139
Development: cfg.EnableDevelopmentLogging,
145140
Level: lvl,
141+
TimeEncoder: zapcore.ISO8601TimeEncoder,
146142
}
147143
ctrlrt.SetLogger(zap.New(zap.UseFlagOptions(&zapOptions)))
148144
}

0 commit comments

Comments
 (0)