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

ctx: Modify WithContext to use a non-pointer receiver #409

Merged
merged 1 commit into from Feb 24, 2022

Conversation

nickcorin
Copy link
Contributor

@nickcorin nickcorin commented Feb 4, 2022

This PR addresses the issues discussed in #116 and #400.

I have modified the receiver for WithContext to use a non-pointer receiver and fixed the tests.

The alternative to this, as discussed, would be to modify Logger() to return a pointer. If this is the preferred fix, I'd be happy to implement. However, it will have more knock-on effects.

Fixes #116.

@pschwartz
Copy link

Watching to see status as I am making use of this and breaking down into multiple statements including a .UpdateContext() is not as clean as the single line.

@rs rs merged commit 588a61c into rs:master Feb 24, 2022
@nickcorin nickcorin deleted the issue-400/with-context-non-pointer branch February 24, 2022 06:57
yfuruyama added a commit to yfuruyama/crzerolog that referenced this pull request Sep 19, 2022
yfuruyama added a commit to yfuruyama/crzerolog that referenced this pull request Sep 19, 2022
pablitoc pushed a commit to nxcr-org/zerolog that referenced this pull request Apr 7, 2023
if lp, ok := ctx.Value(ctxKey{}).(*Logger); ok {
if lp == l {
if lp == &l {
Copy link
Contributor

Choose a reason for hiding this comment

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

So this change makes no sense. Value receiver methods get a new copy of l every time they are called. So here you are taking an address of this temporary copied value and comparing it with context pointer. This will always be false. This has been fixed by removing this check in #499.

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.

Chaining WithContext call is broken
4 participants