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

Leveled fields: Fields present only at certain log levels #1251

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ChannyClaus
Copy link
Contributor

@ChannyClaus ChannyClaus commented Mar 18, 2023

#1078

Added just DebugField for now per the suggestions in the issue. Extending this should be very straight-forward if need be.

@@ -106,6 +106,7 @@ type Field struct {
Type FieldType
Integer int64
String string
Level *Level
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making this attribute a pointer seemed the cleanest way to implement this - doing so would make all existing fields' Level attribute be nil.

field.go Outdated
@@ -35,8 +35,17 @@ type Field = zapcore.Field
var (
_minTimeInt64 = time.Unix(0, math.MinInt64)
_maxTimeInt64 = time.Unix(0, math.MaxInt64)

DebugLevelField = zapcore.DebugLevel
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needed to duplicate this in order to be able to pass the address of the DebugLevel for assignment (https://github.com/uber-go/zap/pull/1251/files#diff-b494c03820a49f9efc491691ed31a2acc16d4cebf39d679ffd74bf97bbee968bR45)

DebugLevel doesn't work because https://github.com/uber-go/zap/blob/master/level.go#L32 already uses that name in the same package.

@codecov
Copy link

codecov bot commented Mar 18, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.09%. Comparing base (845ca51) to head (175582f).
Report is 82 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1251   +/-   ##
=======================================
  Coverage   98.08%   98.09%           
=======================================
  Files          50       50           
  Lines        3240     3252   +12     
=======================================
+ Hits         3178     3190   +12     
  Misses         53       53           
  Partials        9        9           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@prashantv prashantv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing this in the ioCore means that this won't work with other cores. For example, this won't work with zaptest/observer.

Edit: I think the implementation of this could live in CheckedEntry to work with all cores.

@ChannyClaus
Copy link
Contributor Author

ChannyClaus commented Apr 17, 2023

Doing this in the ioCore means that this won't work with other cores. For example, this won't work with zaptest/observer.

ah darn - thanks for taking a look! will look into it when i get a chance :.)

@ChannyClaus ChannyClaus requested a review from prashantv April 18, 2023 01:18
@ChannyClaus
Copy link
Contributor Author

ChannyClaus commented Apr 18, 2023

@prashantv moved the filtering over to where you pointed out in the comment - sorry about the incorrect change earlier.

not super sure if https://github.com/uber-go/zap/pull/1251/files#diff-4a689f7bcb3f92ee8d87b3d9070215a7fcb37680843003657a60357c6a821d90R273 is also necessary since all invocations of OnWrite seem to not use the field argument:

$ git grep 'func.*OnWrite'
logger_test.go:func (h *customWriteHook) OnWrite(_ *zapcore.CheckedEntry, _ []Field) {
zapcore/entry.go:func (a CheckWriteAction) OnWrite(ce *CheckedEntry, _ []Field) {
zapcore/entry_test.go:func (c *customHook) OnWrite(_ *CheckedEntry, _ []Field) {

let me know what you think!

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