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

Not mutate global zerolog.LevelFieldName #7

Merged
merged 3 commits into from Nov 22, 2021
Merged

Not mutate global zerolog.LevelFieldName #7

merged 3 commits into from Nov 22, 2021

Conversation

hn8
Copy link
Contributor

@hn8 hn8 commented Nov 21, 2021

#6

@hn8 hn8 requested review from pohly and thockin November 21, 2021 15:41
@@ -45,6 +45,7 @@ func helper2(log logr.Logger, msg string) {

func ExampleNew() {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
zerolog.LevelFieldName = ""
Copy link
Collaborator

Choose a reason for hiding this comment

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

You have to add this to get the test to pass, right? That implies that the change in NewLogSink is a breaking change.

We'll need a NewLogSinkWithOptions and leave NewLogSink unchanged.

Copy link
Contributor Author

@hn8 hn8 Nov 22, 2021

Choose a reason for hiding this comment

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

Normally I agree that we need to avoid breaking change, but this PR is to fix a bug that users can not see any level or v field in the codepath not using logr/zerologr. And restoring level field is less likely to break code than removing field.

@hn8 hn8 marked this pull request as draft November 22, 2021 01:43
@hn8
Copy link
Contributor Author

hn8 commented Nov 22, 2021

@thockin @pohly As I explained in the issue #6, this PR is to restore level key to NOT breaking zerolog API, otherwises there is no level and v field in the codepath using zerolog without zerologr. NewWithOptions may not be necessary since DisableZerologLevelField is just mutating zerolog.LevelFieldName globally, so IMHO we can add NewWithOptions later when we have options to apply on LogSink struct.

Restoring level field will make zerologr consistent with zapr. If users who use logr in all parts of application think level field and v field are redundant, they can disable zerolog.LevelFieldName and zapcore.OmitKey (or we can do a better job documenting it)

@hn8 hn8 marked this pull request as ready for review November 22, 2021 11:35
@hn8 hn8 requested a review from pohly November 22, 2021 11:35
@thockin
Copy link
Collaborator

thockin commented Nov 22, 2021

I see. I had it backwards.

@thockin thockin merged commit 92a2ed7 into master Nov 22, 2021
@hn8 hn8 deleted the level-field branch November 22, 2021 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants