You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The encoder somewhat breaks namespacing that zap provides, since it appends the namespace foo to the msg key (and others) as well. This is not the case in the zap package.
Compare the output of logfmt (from this plugin):
database.ts=2022-11-25T13:50:59.759+0100 database.level=info database.caller=cmd/root.go:150 database.msg="initializing DB connection"
to standard json encoding via zap package:
{"level":"info","ts":"2022-11-25T13:52:12.539+0100","caller":"cmd/root.go:150","msg":"initializing DB connection","app_name":"main","app_version":"snapshot","database":{"host": ... }}
The solution would be something along the lines of
func (enc *logfmtEncoder) addKey(key string) {
if enc.buf.Len() > 0 {
enc.buf.AppendByte(' ')
}
switch key {
case enc.EncoderConfig.TimeKey, enc.EncoderConfig.LevelKey, enc.EncoderConfig.NameKey, enc.EncoderConfig.CallerKey, enc.EncoderConfig.MessageKey, enc.EncoderConfig.StacktraceKey:
default:
for _, ns := range enc.namespaces {
enc.safeAddString(ns)
enc.buf.AppendByte('.')
}
}
enc.safeAddString(key)
enc.buf.AppendByte('=')
}
Let me know if I should open a PR.
The text was updated successfully, but these errors were encountered:
The encoder somewhat breaks namespacing that
zap
provides, since it appends the namespacefoo
to themsg
key (and others) as well. This is not the case in thezap
package.Compare the output of
logfmt
(from this plugin):to standard
json
encoding viazap
package:The solution would be something along the lines of
Let me know if I should open a PR.
The text was updated successfully, but these errors were encountered: