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 WithPanicHook logger option for panic log tests #1416

Merged
merged 1 commit into from Feb 20, 2024

Conversation

MKrupauskas
Copy link
Contributor

@MKrupauskas MKrupauskas commented Feb 9, 2024

Add a WithPanicHook logger option that allows callers to specify custom behavior besides panicking on Panic/DPanic logs. This is similar to what we already have with the WithFatal hook implemented in #861.

This will make it possible to unit test Panic log cases like the one we had with our periodic runner which was impossible because of unrecoverable panics in another go routine.

Added unit tests and they pass.

$ make test
?       go.uber.org/zap/internal        [no test files]
?       go.uber.org/zap/internal/bufferpool     [no test files]
ok      go.uber.org/zap (cached)
?       go.uber.org/zap/internal/readme [no test files]
ok      go.uber.org/zap/buffer  (cached)
ok      go.uber.org/zap/internal/color  (cached)
ok      go.uber.org/zap/internal/exit   (cached)
ok      go.uber.org/zap/internal/pool   (cached)
ok      go.uber.org/zap/internal/stacktrace     (cached)
ok      go.uber.org/zap/internal/ztest  (cached)
ok      go.uber.org/zap/zapcore (cached)
ok      go.uber.org/zap/zapgrpc (cached)
ok      go.uber.org/zap/zapio   (cached)
ok      go.uber.org/zap/zaptest (cached)
ok      go.uber.org/zap/zaptest/observer        (cached)
ok      go.uber.org/zap/exp/zapfield    (cached)
ok      go.uber.org/zap/exp/zapslog     (cached)
ok      go.uber.org/zap/benchmarks      (cached) [no tests to run]
ok      go.uber.org/zap/zapgrpc/internal/test   (cached)

Closes #1415

@sywhang sywhang self-requested a review February 16, 2024 18:30
Copy link

codecov bot commented Feb 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (e5745d6) 98.44% compared to head (7a4359b) 98.44%.
Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1416   +/-   ##
=======================================
  Coverage   98.44%   98.44%           
=======================================
  Files          53       53           
  Lines        3527     3531    +4     
=======================================
+ Hits         3472     3476    +4     
  Misses         46       46           
  Partials        9        9           

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

@abhinav
Copy link
Collaborator

abhinav commented Feb 20, 2024

Thanks! This makes sense to me.
Will wait for other maintainers for a second review and merge.

CC @r-hang @sywhang

Copy link
Contributor

@sywhang sywhang left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@sywhang sywhang merged commit e5a56ee into uber-go:master Feb 20, 2024
8 checks passed
@MKrupauskas
Copy link
Contributor Author

Thanks for the reviews folks!

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.

Support specifying a custom onPanic logger hook for tests
3 participants