-
Notifications
You must be signed in to change notification settings - Fork 557
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invalid json when using only an objet #152
Comments
The bug is actually triggered if Object is the first pushed to the logger, i.e: logger := zerolog.New(os.Stdout).With().Object("foo", foo{}).Str("bar", "foo").Logger()
logger.Info().Msg("qux") Problem seems to come from func (Encoder) AppendObjectData(dst []byte, o []byte) []byte {
if o[0] == '{' {
if len(dst) == 0 {
o = o[1:]
} else {
o[0] = ','
}
} else if len(dst) > 1 {
dst = append(dst, ',')
}
return append(dst, o...)
} |
With some comment is should be ok. If you can add unit test too, it would be awesome (considering you are willing to send a PR). |
I can do that :) give me a bit of time to implement it |
When pushing an object to the logger, and this object was the first field added. Zerolog was outputting an invalid json blob, issuing an extra comma before the object. This patch ensure that JSON is still valid even if an object is pushed first to the logger. Fixes rs#152
When pushing an object to the logger, and this object was the first field added. Zerolog was outputting an invalid json blob, issuing an extra comma before the object. This patch ensure that JSON is still valid even if an object is pushed first to the logger. Fixes rs#152
When pushing an object to the logger, and this object was the first field added. Zerolog was outputting an invalid json blob, issuing an extra comma before the object. This patch ensure that JSON is still valid even if an object is pushed first to the logger. Fixes rs#152
Is there anything I need to add? |
When pushing an object to the logger, and this object was the first field added. Zerolog was outputting an invalid json blob, issuing an extra comma before the object. This patch ensure that JSON is still valid even if an object is pushed first to the logger. Fixes #152
When I use zerolog with only an object the json output is incorrect.
This will output:
When pushing any additional field other than object:
I get a valid json:
The text was updated successfully, but these errors were encountered: