Skip to content
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

Merged
merged 2 commits into from
Aug 17, 2017

Conversation

prashantv
Copy link
Collaborator

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

@prashantv prashantv requested a review from akshayjshah August 15, 2017 23:28
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`
@codecov
Copy link

codecov bot commented Aug 15, 2017

Codecov Report

Merging #490 into master will increase coverage by 0.1%.
The diff coverage is 100%.

Impacted file tree graph

@@           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
Impacted Files Coverage Δ
zaptest/observer/observer.go 100% <ø> (ø) ⬆️
zaptest/observer/logged_entry.go 100% <100%> (ø)
stacktrace.go 93.58% <0%> (+8.22%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e68420e...ee45802. Read the comment docs.

f.AddTo(encoder)
}
return encoder.Fields
}
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

Copy link
Contributor

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().

Copy link
Collaborator Author

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

@prashantv prashantv changed the title Add function to convert []Field to map[string]interface{} Add ContextMap method to LoggedEntry which returns fields as a map Aug 17, 2017
@prashantv prashantv merged commit 51996d5 into master Aug 17, 2017
@prashantv prashantv deleted the observer_fields branch August 17, 2017 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants