Hello I want to use zap global logger
Right now I am using sugar_logger like this
log_sugar.Infow("Start API",
"protocol", "http",
"host", config.Host,
)
And response is {"level":"info","ts":1638893668.7487385,"caller":"root/main.go:97","msg":"Start API.","host":"0.0.0.0:8080","protocol":"http","host":"0.0.0.0:8080"}
but I want to use like this zap.L().Info("replaced zap's global loggers")
when I use like this
zap.L().Info("Start API",
"protocol", "http",
"host", config.Host,
)
I get an error "too many arguments" how can I use global logger, what am I doing wrong
Thank you
CodePudding user response:
https://pkg.go.dev/go.uber.org/zap#Logger takes a format string
and a list of zap.Field
s.
zap.L().Info("Start API",
zap.String("protocol","http"),
zap.String("host",config.Host),
)
"too many arguments" because zap.Info
takes a string and a variadic list of Field
s, but you included too many strings and no Field
s. The string
s can't be Field
s, so they ended up being extra string arguments and that doesn't fit the function signature.