-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jsonEncoder: Close namespaces opened in an object (#1017)
A bug in the implementation of jsonEncoder did not close namespaces opened inside a MarshalLogObject method when the method exited. It waited until the entire entry was encoded. For example, type foo struct{ ... } func (*foo) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.OpenNamespace("ns") enc.AddString("x", "y") return nil } log.Info("msg", zap.Object("foo", &foo{..}), zap.Int("bar", 1)) We expect, {"msg": "msg", "foo": {"ns": {"x": "y"}}, "bar": 1} But with the JSON encoder, we currently get, {"msg": "msg", "foo": {"ns": {"x": "y"}, "bar": 1}} (`"bar"` has become part of the "ns" object created in "foo".) This resolves the issue by tracking the number of namespaces for each nested object separately, and closing only those namespaces that were created during that object's MarshalLogObject call. Resolves #554
- Loading branch information
1 parent
2216968
commit b62116b
Showing
3 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters