File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -49,5 +49,23 @@ pub fn setup()
4949 . with ( console_log_layer)
5050 . init ( ) ;
5151
52+ std:: panic:: set_hook ( Box :: new ( |panic| {
53+ // If the panic has a source location, record it as structured fields.
54+ if let Some ( location) = panic. location ( ) {
55+ // On nightly Rust, where the `PanicInfo` type also exposes a
56+ // `message()` method returning just the message, we could record
57+ // just the message instead of the entire `fmt::Display`
58+ // implementation, avoiding the duplicated location
59+ tracing:: error!(
60+ message = %panic,
61+ panic. file = location. file( ) ,
62+ panic. line = location. line( ) ,
63+ panic. column = location. column( ) ,
64+ ) ;
65+ } else {
66+ tracing:: error!( message = %panic) ;
67+ }
68+ } ) ) ;
69+
5270 Ok ( ( console_guard, file_guard) )
5371}
You can’t perform that action at this time.
0 commit comments