tracing-test
tracing-test copied to clipboard
opt-in triggering panic on `Level::ERROR` traces
When working with complicated tests where deep in the code error logs are written, it would be useful if this crate offered a function that sets a tracing subscriber that panics on error events.
I wrote a naive one myself for tests of a bevy-related crate that looks like this:
fn panic_on_error_events() {
struct PanicOnError;
impl<S: Subscriber> Layer<S> for PanicOnError {
fn on_event(&self, event: &Event, _ctx: Context<S>) {
if *event.metadata().level() == Level::ERROR {
panic!("{event:#?}")
}
}
}
if registry().with(PanicOnError).try_init().is_err() {
get_default(|subscriber| {
assert!(subscriber.downcast_ref::<PanicOnError>().is_some());
})
}
}