-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add ContextMap method to LoggedEntry which returns fields as a map #490
Conversation
Tests often care about specific fields, or want fields without worrying about order, or marshalling objects etc. It makes more sense for tests to compare a fields `map[string]interface{}` rather than `[]zap.Field`
40b15b3
to
83a3834
Compare
Codecov Report
@@ Coverage Diff @@
## master #490 +/- ##
=======================================
+ Coverage 96.9% 97% +0.1%
=======================================
Files 36 37 +1
Lines 2197 2240 +43
=======================================
+ Hits 2129 2173 +44
+ Misses 59 58 -1
Partials 9 9
Continue to review full report at Codecov.
|
zaptest/observer/fields.go
Outdated
f.AddTo(encoder) | ||
} | ||
return encoder.Fields | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love the implementation. Would this be more ergonomic as a ContextMap
method on LoggedEntry
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to keep this separate from LoggedEntry
since it doesn't have the message or timestamp.
I'm open to ContextMap
, however any underlying nested objects would use map[string]interface{}
. If we're OK with that, I can make this a new ContextMap
type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clarified offline - since the []zapcore.Field
usually comes from LoggedEntry.Context
, we're going to start by exposing this as LoggedEntry.ContextMap()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Misunderstood the comment, moved this method to be a function on LoggedEntry
Tests often care about specific fields, or want fields without worrying
about order, or marshalling objects etc. It makes more sense for tests
to compare a fields
map[string]interface{}
rather than[]zap.Field