Skip to content

Commit c480736

Browse files
Addressed PR comments
1 parent eccba7c commit c480736

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

pkg/log/zap/zap.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ import (
3030
"go.uber.org/zap/zapcore"
3131
)
3232

33-
// EncoderConfigOption is being used to pass options
34-
// for configuring console/json encoder.
33+
// EncoderConfigOption is a function that can modify a `zapcore.EncoderConfig`.
3534
type EncoderConfigOption func(*zapcore.EncoderConfig)
3635

3736
// NewEncoderFunc is a function that creates an Encoder using the provided EncoderConfigOptions.
@@ -105,18 +104,18 @@ func Encoder(encoder zapcore.Encoder) func(o *Options) {
105104
}
106105
}
107106

108-
func newJSONEncoder(ecfs ...EncoderConfigOption) zapcore.Encoder {
107+
func newJSONEncoder(opts ...EncoderConfigOption) zapcore.Encoder {
109108
encoderConfig := zap.NewProductionEncoderConfig()
110-
for _, f := range ecfs {
111-
f(&encoderConfig)
109+
for _, opt := range opts {
110+
opt(&encoderConfig)
112111
}
113112
return zapcore.NewJSONEncoder(encoderConfig)
114113
}
115114

116-
func newConsoleEncoder(ecfs ...EncoderConfigOption) zapcore.Encoder {
115+
func newConsoleEncoder(opts ...EncoderConfigOption) zapcore.Encoder {
117116
encoderConfig := zap.NewDevelopmentEncoderConfig()
118-
for _, f := range ecfs {
119-
f(&encoderConfig)
117+
for _, opt := range opts {
118+
opt(&encoderConfig)
120119
}
121120
return zapcore.NewConsoleEncoder(encoderConfig)
122121
}
@@ -247,7 +246,7 @@ func NewRaw(opts ...Opts) *zap.Logger {
247246
// BindFlags will parse the given flagset for zap option flags and set the log options accordingly
248247
// zap-devel: Development Mode defaults(encoder=consoleEncoder,logLevel=Debug,stackTraceLevel=Warn)
249248
// Production Mode defaults(encoder=jsonEncoder,logLevel=Info,stackTraceLevel=Error)
250-
// zap-encoder: Zap log encoding (Eg., 'json' or 'console')
249+
// zap-encoder: Zap log encoding (one of 'json' or 'console')
251250
// zap-log-level: Zap Level to configure the verbosity of logging. Can be one of 'debug', 'info', 'error',
252251
// or any integer value > 0 which corresponds to custom debug levels of increasing verbosity")
253252
// zap-stacktrace-level: Zap Level at and above which stacktraces are captured (one of 'info' or 'error')
@@ -263,7 +262,7 @@ func (o *Options) BindFlags(fs *flag.FlagSet) {
263262
encVal.setFunc = func(fromFlag NewEncoderFunc) {
264263
o.NewEncoder = fromFlag
265264
}
266-
fs.Var(&encVal, "zap-encoder", "Zap log encoding (Eg., 'json' or 'console')")
265+
fs.Var(&encVal, "zap-encoder", "Zap log encoding (one of 'json' or 'console')")
267266

268267
// Set the Log Level
269268
var levelVal levelFlag

pkg/log/zap/zap_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,8 @@ var _ = Describe("Zap log level flag options setup", func() {
475475
Expect(out.StacktraceLevel).To(BeNil())
476476
Expect(out.EncoderConfigOptions).To(BeNil())
477477
})
478-
It("Should set dev=false with log options.", func() {
479-
args := []string{"--zap-log-level=2"}
478+
It("Should set dev=false", func() {
479+
args := []string{"--zap-devel=false"}
480480
fromFlags.BindFlags(&fs)
481481
if err := fs.Parse(args); err != nil {
482482
Expect(err).ToNot(HaveOccurred())
@@ -485,14 +485,17 @@ var _ = Describe("Zap log level flag options setup", func() {
485485
UseFlagOptions(&fromFlags)(&out)
486486

487487
Expect(out.Development).To(BeFalse())
488-
Expect(out.Level.Enabled(zapcore.ErrorLevel)).To(BeTrue())
488+
Expect(out.Encoder).To(BeNil())
489+
Expect(out.Level).To(BeNil())
490+
Expect(out.StacktraceLevel).To(BeNil())
491+
Expect(out.EncoderConfigOptions).To(BeNil())
489492

490493
})
491494
})
492495

493496
Context("with encoder options provided programmatically.", func() {
494497

495-
It("Should set Console Encoder, with given Nanos TimEncoder option.", func() {
498+
It("Should set Console Encoder, with given Nanos TimeEncoder option.", func() {
496499
logOut := new(bytes.Buffer)
497500
f := func(ec *zapcore.EncoderConfig) {
498501
if err := ec.EncodeTime.UnmarshalText([]byte("nanos")); err != nil {
@@ -512,7 +515,7 @@ var _ = Describe("Zap log level flag options setup", func() {
512515
Expect(string(outRaw)).ShouldNot(ContainSubstring("."))
513516

514517
})
515-
It("Should set JSON Encoder, with given Millis TimEncoder option, and MessageKey", func() {
518+
It("Should set JSON Encoder, with given Millis TimeEncoder option, and MessageKey", func() {
516519
logOut := new(bytes.Buffer)
517520
f := func(ec *zapcore.EncoderConfig) {
518521
ec.MessageKey = "MillisTimeFormat"

0 commit comments

Comments
 (0)