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

Clarify argument capturing behaviour of With #1325

Merged
merged 3 commits into from
Aug 18, 2023

Conversation

jquirke
Copy link
Contributor

@jquirke jquirke commented Aug 18, 2023

Make it clear that the contract with the With and logging methods is such that any arguments that could change are captured at the time of the With and logging method, and that any other behaviour introduced in future is intentionally contrary to this contract.

There are proposed (#1319) future opt-in, changes that will explicitly relax this contract.

@jquirke jquirke force-pushed the clarify-with-captures branch 2 times, most recently from df34488 to 8c6bb33 Compare August 18, 2023 02:29
Make it clear that the contract with the With and logging methods is such that
any arguments that could change are captured at the time of the With and logging
method, and that any other behaviour introduced in future is intentionally
contrary to this contract.

There are proposed (uber-go#1319) future opt-in,
changes that will explicitly relax this contract.
Use a custom encoder that only adds the message and nothing else,
and assert.JSONEq to avoid having to JSON decode into a custom struct.

This also fixes the actual test case:
`b: [1]` should not be present in the second log entry,
because it's not added to the logger.
Copy link
Collaborator

@abhinav abhinav left a comment

Choose a reason for hiding this comment

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

Great! I tweaked the test a bit: assert.JSONEq plus an encoder that doesn't include time so that we don't have to json.Unmarshal.

Also, the test case was a bit off: b: [1] will not be present in the second entry
because Array("b", ..) was only used with the logger.Info, not logger.With.

@codecov
Copy link

codecov bot commented Aug 18, 2023

Codecov Report

Merging #1325 (e959f3b) into master (c94c2bb) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master    #1325   +/-   ##
=======================================
  Coverage   97.77%   97.77%           
=======================================
  Files          51       51           
  Lines        3366     3366           
=======================================
  Hits         3291     3291           
  Misses         65       65           
  Partials       10       10           
Files Changed Coverage Δ
logger.go 96.55% <ø> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@abhinav abhinav requested review from mway and sywhang August 18, 2023 20:48
@abhinav abhinav merged commit 02ebf0f into uber-go:master Aug 18, 2023
5 checks passed
@rabbbit
Copy link
Contributor

rabbbit commented Aug 19, 2023

I'm late, but thanks for doing this!

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.

3 participants