-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 options to customize Fatal behaviour for better testability #861
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Fixes #846. There's currently no easy way to test Fatal from outside of zap, as it triggers an os.Exit(1). Add options to customize the behaviour (allowing for panic, or Goexit), which can be used with `recover()` in tests.
Codecov Report
@@ Coverage Diff @@
## master #861 +/- ##
==========================================
+ Coverage 98.35% 98.37% +0.01%
==========================================
Files 43 43
Lines 2378 2393 +15
==========================================
+ Hits 2339 2354 +15
Misses 32 32
Partials 7 7
Continue to review full report at Codecov.
|
abhinav
reviewed
Sep 1, 2020
Co-authored-by: Abhinav Gupta <abg@uber.com>
Co-authored-by: Abhinav Gupta <abg@uber.com>
abhinav
approved these changes
Sep 1, 2020
cgxxv
pushed a commit
to cgxxv/zap
that referenced
this pull request
Mar 25, 2022
…-go#861) Fixes uber-go#846. There's currently no easy way to test Fatal from outside of zap, as it triggers an os.Exit(1). Add options to customize the behaviour (allowing for panic, or Goexit), which can be used with `recover()` in tests.
sywhang
pushed a commit
that referenced
this pull request
Feb 20, 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #846.
There's currently no easy way to test Fatal from outside of zap, as it
triggers an os.Exit(1). Add options to customize the behaviour (allowing
for panic, or Goexit), which can be used with
recover()
in tests.