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
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions example/example_test.go
Expand Up @@ -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.

zl := zerolog.New(os.Stdout)
log := zerologr.New(&zl)
log = log.WithName("MyName")
Expand Down
3 changes: 0 additions & 3 deletions zerologr.go
Expand Up @@ -72,9 +72,6 @@ func New(l *zerolog.Logger) Logger {

// NewLogSink returns a logr.LogSink implemented by Zerolog.
func NewLogSink(l *zerolog.Logger) *LogSink {
if zerolog.LevelFieldName == "level" {
zerolog.LevelFieldName = ""
}
return &LogSink{l: l}
}

Expand Down