Skip to content

Commit

Permalink
Merge pull request #1206 from alvaroaleman/add-encoders
Browse files Browse the repository at this point in the history
✨ Zap: Add JSONEncoder and ConsoleEncoder opts
  • Loading branch information
k8s-ci-robot committed Oct 2, 2020
2 parents af2f5b1 + 96f8f3a commit 0e13441
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/log/zap/zap.go
Expand Up @@ -71,6 +71,13 @@ func Encoder(encoder zapcore.Encoder) func(o *Options) {
}
}

// JSONEncoder configures the logger to use a JSON Encoder
func JSONEncoder(opts ...EncoderConfigOption) func(o *Options) {
return func(o *Options) {
o.Encoder = newJSONEncoder(opts...)
}
}

func newJSONEncoder(opts ...EncoderConfigOption) zapcore.Encoder {
encoderConfig := zap.NewProductionEncoderConfig()
for _, opt := range opts {
Expand All @@ -79,6 +86,13 @@ func newJSONEncoder(opts ...EncoderConfigOption) zapcore.Encoder {
return zapcore.NewJSONEncoder(encoderConfig)
}

// ConsoleEncoder configures the logger to use a Console encoder
func ConsoleEncoder(opts ...EncoderConfigOption) func(o *Options) {
return func(o *Options) {
o.Encoder = newConsoleEncoder(opts...)
}
}

func newConsoleEncoder(opts ...EncoderConfigOption) zapcore.Encoder {
encoderConfig := zap.NewDevelopmentEncoderConfig()
for _, opt := range opts {
Expand Down

0 comments on commit 0e13441

Please sign in to comment.