Skip to content

Commit

Permalink
Delegate reflected encoder to callee (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
liranbg authored Jan 18, 2022
1 parent a9281bb commit eff6acb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/nuclio/zap
go 1.17

require (
github.com/goccy/go-json v0.9.3
github.com/liranbg/uberzap v1.20.0-nuclio.1
github.com/logrusorgru/aurora/v3 v3.0.0
github.com/nuclio/errors v0.0.3
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZx
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/goccy/go-json v0.9.3 h1:VYKeLtdIQXWaeTZy5JNGZbVui5ck7Vf5MlWEcflqz0s=
github.com/goccy/go-json v0.9.3/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand Down
31 changes: 15 additions & 16 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"strings"
"time"

gojson "github.com/goccy/go-json"
"github.com/liranbg/uberzap"
"github.com/liranbg/uberzap/zapcore"
"github.com/logrusorgru/aurora/v3"
Expand All @@ -46,6 +45,7 @@ type EncoderConfigJSON struct {
VarGroupMode VarGroupMode
TimeFieldName string
TimeFieldEncoding string
ReflectedEncoder func(writer io.Writer) zapcore.ReflectedEncoder
}

type EncoderConfigConsole struct {
Expand All @@ -63,6 +63,7 @@ func NewEncoderConfig() *EncoderConfig {
TimeFieldName: "time",
TimeFieldEncoding: "epoch-millis",
VarGroupMode: DefaultVarGroupMode,
ReflectedEncoder: nil,
},
}
}
Expand Down Expand Up @@ -408,21 +409,19 @@ func (nz *NuclioZap) getEncoderConfig(encoding string, encoderConfig *EncoderCon
}

return &zapcore.EncoderConfig{
TimeKey: encoderConfig.JSON.TimeFieldName,
NameKey: "name",
LevelKey: "level",
CallerKey: "",
MessageKey: "message",
StacktraceKey: "stack",
LineEnding: encoderConfig.JSON.LineEnding,
EncodeLevel: zapcore.LowercaseLevelEncoder,
EncodeTime: timeEncoder,
EncodeDuration: zapcore.SecondsDurationEncoder,
EncodeCaller: func(zapcore.EntryCaller, zapcore.PrimitiveArrayEncoder) {},
EncodeName: zapcore.FullNameEncoder,
NewReflectedEncoder: func(writer io.Writer) zapcore.ReflectedEncoder {
return gojson.NewEncoder(writer)
},
TimeKey: encoderConfig.JSON.TimeFieldName,
NameKey: "name",
LevelKey: "level",
CallerKey: "",
MessageKey: "message",
StacktraceKey: "stack",
LineEnding: encoderConfig.JSON.LineEnding,
EncodeLevel: zapcore.LowercaseLevelEncoder,
EncodeTime: timeEncoder,
EncodeDuration: zapcore.SecondsDurationEncoder,
EncodeCaller: func(zapcore.EntryCaller, zapcore.PrimitiveArrayEncoder) {},
EncodeName: zapcore.FullNameEncoder,
NewReflectedEncoder: encoderConfig.JSON.ReflectedEncoder,
}
}

Expand Down

0 comments on commit eff6acb

Please sign in to comment.