Skip to content

Commit 0e13441

Browse files
authored
Merge pull request #1206 from alvaroaleman/add-encoders
✨ Zap: Add JSONEncoder and ConsoleEncoder opts
2 parents af2f5b1 + 96f8f3a commit 0e13441

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pkg/log/zap/zap.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ func Encoder(encoder zapcore.Encoder) func(o *Options) {
7171
}
7272
}
7373

74+
// JSONEncoder configures the logger to use a JSON Encoder
75+
func JSONEncoder(opts ...EncoderConfigOption) func(o *Options) {
76+
return func(o *Options) {
77+
o.Encoder = newJSONEncoder(opts...)
78+
}
79+
}
80+
7481
func newJSONEncoder(opts ...EncoderConfigOption) zapcore.Encoder {
7582
encoderConfig := zap.NewProductionEncoderConfig()
7683
for _, opt := range opts {
@@ -79,6 +86,13 @@ func newJSONEncoder(opts ...EncoderConfigOption) zapcore.Encoder {
7986
return zapcore.NewJSONEncoder(encoderConfig)
8087
}
8188

89+
// ConsoleEncoder configures the logger to use a Console encoder
90+
func ConsoleEncoder(opts ...EncoderConfigOption) func(o *Options) {
91+
return func(o *Options) {
92+
o.Encoder = newConsoleEncoder(opts...)
93+
}
94+
}
95+
8296
func newConsoleEncoder(opts ...EncoderConfigOption) zapcore.Encoder {
8397
encoderConfig := zap.NewDevelopmentEncoderConfig()
8498
for _, opt := range opts {

0 commit comments

Comments
 (0)