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 context support #27

Merged
merged 1 commit into from
Oct 24, 2020
Merged

Add context support #27

merged 1 commit into from
Oct 24, 2020

Conversation

iand
Copy link
Contributor

@iand iand commented Oct 20, 2020

Fixes #25

Cannot be merged until there is a null logger implementation, see #26

I can add as part of this PR if that helps.

logr.go Outdated
return v
}

return nullLogger{}
Copy link
Contributor

Choose a reason for hiding this comment

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

From #25:

I think the contract here should be "returns the context's Logger or nil if no Logger is in the context". Libs which expect a Logger should say so and make callers provide one. I know DI is not really Go-ish, but it has saved my butt many times.

Offering a NullLogger (#26) and automatically using it are 2 very different things.

Just return nil here and make the comment clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think a disabled logger is a better experience. Then there is no difference for library code between getting a logger that has been disabled manually due to V or not having a logger in the context. Otherwise we force everyone to perform a nil check every time they obtain a logger from a context.

Copy link
Contributor

Choose a reason for hiding this comment

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

Github email put this on the conversation rather than here.

I understand that you think that. We disagree on this point and that is
OK. I'm a fan of low-magic and obvious errors.

If it turns out I am wrong (it happens at least daily, ask my kids!) this
can probably be changed with relative ease.

Copy link
Contributor

Choose a reason for hiding this comment

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

As mentioned in #25: we could add simple FromContext() and FromContextOrNull() which does what you describe, I guess.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll implement whatever the agreed consensus is on #25

Copy link
Contributor

Choose a reason for hiding this comment

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

#26 is merged and I think we're at consensus on #25 ?

@iand
Copy link
Contributor Author

iand commented Oct 23, 2020

Updated to the consensus in #25, PTAL

logr.go Outdated Show resolved Hide resolved
@thockin
Copy link
Contributor

thockin commented Oct 23, 2020

Just one super tiny comment change and I am happy

@thockin thockin merged commit 4fa77cb into go-logr:master Oct 24, 2020
@thockin
Copy link
Contributor

thockin commented Oct 24, 2020

Thanks!

@bbiao
Copy link

bbiao commented Nov 2, 2020

Hi, when will this be released? My project depends on this feature, happy to know the release date.

@thockin
Copy link
Contributor

thockin commented Nov 2, 2020 via email

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.

Context support
3 participants