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

add support for iso8601 timestamps #1529

Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a236758
add support for iso8601 timestamps
otakumike Jun 7, 2019
104ad86
Update pkg/log/zap/flags.go
ironmike-au Jun 12, 2019
09ef1c9
Merge branch 'master' of https://github.com/operator-framework/operat…
otakumike Jun 12, 2019
233c09a
Merge branch 'master' into feature/add-iso8601-timestamp-support
otakumike Jun 12, 2019
0d01734
timeformat flag accepts zapcore formats
otakumike Jun 13, 2019
99d3d68
add --zap-timeformat usage doc
otakumike Jun 13, 2019
318a7dc
Update pkg/log/zap/flags.go
ironmike-au Jun 13, 2019
bcb2c7f
expand log encoder support functional options and passing multiple en…
otakumike Jun 13, 2019
ffc3558
fix encoder references in tests
otakumike Jun 13, 2019
599d633
fix encoder references in tests
otakumike Jun 13, 2019
69d4514
Update doc/user/logging.md
ironmike-au Jun 13, 2019
a6cc1b1
set the encoder in both the json and console cases
otakumike Jun 13, 2019
1e5dfee
use zap's time encoding UnmarshalText functionality to avoid manually…
otakumike Jun 13, 2019
448d1c8
rename timeformat to timeencoding/er so that it is consistent with za…
otakumike Jun 13, 2019
d4ffca5
rename timeformat to timeencoding/er so that it is consistent with za…
otakumike Jun 13, 2019
291452c
add basic tests for zap time encoding
otakumike Jun 14, 2019
62e63ff
Merge branch 'master' into feature/add-iso8601-timestamp-support
ironmike-au Jun 25, 2019
e08a62e
Merge branch 'master' into feature/add-iso8601-timestamp-support
joelanford Jul 31, 2019
12a0110
pkg/log/zap/*: test improvements for sampling and encoders
joelanford Jul 31, 2019
77dfc60
pkg/log/zap/flags*: timeEncoder Unmarshal comments/improvements
joelanford Jul 31, 2019
2a09af3
doc/user/logging.md: fix zap-time-encoding flag name
joelanford Jul 31, 2019
e108039
CHANGELOG.md,doc/user/logging.md: doc updates
joelanford Jul 31, 2019
c993d21
Merge branch 'master' into feature/add-iso8601-timestamp-support
joelanford Aug 1, 2019
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
47 changes: 43 additions & 4 deletions pkg/log/zap/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ import (
var (
zapFlagSet *pflag.FlagSet

development bool
encoderVal encoderValue
levelVal levelValue
sampleVal sampleValue
development bool
encoderVal encoderValue
levelVal levelValue
sampleVal sampleValue
timeformatVal timeformatValue
)

func init() {
Expand All @@ -41,6 +42,7 @@ func init() {
zapFlagSet.Var(&encoderVal, "zap-encoder", "Zap log encoding ('json' or 'console')")
zapFlagSet.Var(&levelVal, "zap-level", "Zap log level (one of 'debug', 'info', 'error' or any integer value > 0)")
zapFlagSet.Var(&sampleVal, "zap-sample", "Enable zap log sampling. Sampling will be disabled for integer log levels > 1")
zapFlagSet.Var(&timeformatVal, "zap-timeformat", "Use 'unix' or 'iso8601' time formatting. 'unix' is the default.")
ironmike-au marked this conversation as resolved.
Show resolved Hide resolved
}

// FlagSet - The zap logging flagset.
Expand Down Expand Up @@ -78,11 +80,17 @@ func (v encoderValue) Type() string {

func jsonEncoder() zapcore.Encoder {
encoderConfig := zap.NewProductionEncoderConfig()
if timeformatVal.String() == "iso8601" {
encoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
}
joelanford marked this conversation as resolved.
Show resolved Hide resolved
return zapcore.NewJSONEncoder(encoderConfig)
}

func consoleEncoder() zapcore.Encoder {
encoderConfig := zap.NewDevelopmentEncoderConfig()
if timeformatVal.String() == "iso8601" {
encoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
}
return zapcore.NewConsoleEncoder(encoderConfig)
}

Expand Down Expand Up @@ -158,3 +166,34 @@ func (v sampleValue) IsBoolFlag() bool {
func (v sampleValue) Type() string {
return "sample"
}

type timeformatValue struct {
joelanford marked this conversation as resolved.
Show resolved Hide resolved
set bool
str string
joelanford marked this conversation as resolved.
Show resolved Hide resolved
}

func (v *timeformatValue) Set(s string) error {
v.set = true
if len(s) > 1 {
if s == "unix" || s == "iso8601" {
joelanford marked this conversation as resolved.
Show resolved Hide resolved
v.str = s
return nil
}
return fmt.Errorf("unknown timeformat \"%s\"", s)
ironmike-au marked this conversation as resolved.
Show resolved Hide resolved

}
v.str = "unix"
return nil
}

func (v timeformatValue) String() string {
return v.str
}

func (v timeformatValue) IsBoolFlag() bool {
return false
}

func (v timeformatValue) Type() string {
return "string"
joelanford marked this conversation as resolved.
Show resolved Hide resolved
}