You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There can be complications when testing Panic/DPanic logs similarly to Fatal logs as described in #846.
For example, it's impossible to recover from a logger.Panic in a tests if that log is emitted in another go routine. This is exactly the case with our periodic runner library.
The best approach we came up with was extending zap to support passing a custom onPanic hook like we have for onFatal.
The text was updated successfully, but these errors were encountered:
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
There can be complications when testing Panic/DPanic logs similarly to Fatal logs as described in #846.
For example, it's impossible to recover from a logger.Panic in a tests if that log is emitted in another go routine. This is exactly the case with our periodic runner library.
The best approach we came up with was extending zap to support passing a custom onPanic hook like we have for onFatal.
The text was updated successfully, but these errors were encountered: