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

Extend WithLazy() method to SugaredLogger #1378

Merged
merged 2 commits into from Nov 25, 2023

Conversation

defval
Copy link
Contributor

@defval defval commented Oct 31, 2023

Hey there! Resolves #1377

Notes:

  • I reused all tests from the With() method to work with both With() and WithLazy()
  • To highlight the differences between With() and WithLazy(), I added a test similar to this one. I kept only the test cases that clearly show the distinctions

Looking forward to your thoughts!

@CLAassistant
Copy link

CLAassistant commented Oct 31, 2023

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@r-hang r-hang left a comment

Choose a reason for hiding this comment

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

Sorry for the delay, the implementation looks good. I think we should at least add tests for interleaved With and WithLazy calls, what do you think?

sugar_test.go Outdated
},
},
{
name: "lazy with captures arguments at time of With or Logging",
Copy link
Contributor

Choose a reason for hiding this comment

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

I suspect that this may be a typo in the original zap.Logger PR, but I think the test case name should be "lazy with captures arguments at time of Logging"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I think so, fixed

},
}

for _, tt := range tests {
Copy link
Contributor

Choose a reason for hiding this comment

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

https://github.com/uber-go/zap/pull/1319/files also has a few more scenarios for the capture tests. While you are testing some aspect of chained With and WithLazy, I think it makes sense to also test interleaved calls of With then WithLazy and vis-versa as well.

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 was actually thinking about including those interleaved With and WithLazy tests at first. But then I thought, since lazyWithCore already covers what we need, maybe it’s better not to repeat the same stuff? I just focused on showing how With and WithLazy are different, especially with how WithLazy uses that extra core.

I'm totally fine with adding more tests if it really helps. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that there would be testing overlap between the two loggers.

I think it would be nice for zap to set up testing in a way that would be easy to verify sugared and non sugared behavior through the same process where they should be similar. However, that doesn't need to be part of this change.

Copy link

codecov bot commented Nov 25, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (87577d8) 98.28% compared to head (bf375e8) 98.42%.
Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1378      +/-   ##
==========================================
+ Coverage   98.28%   98.42%   +0.14%     
==========================================
  Files          53       53              
  Lines        3493     3495       +2     
==========================================
+ Hits         3433     3440       +7     
+ Misses         50       46       -4     
+ Partials       10        9       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@r-hang r-hang left a comment

Choose a reason for hiding this comment

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

thank you for the contribution!

},
}

for _, tt := range tests {
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that there would be testing overlap between the two loggers.

I think it would be nice for zap to set up testing in a way that would be easy to verify sugared and non sugared behavior through the same process where they should be similar. However, that doesn't need to be part of this change.

@r-hang r-hang merged commit fa1b6ae into uber-go:master Nov 25, 2023
6 checks passed
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.

Extend WithLazy method to SugaredLogger
3 participants