Install a panic handler that prints stuff to the logs, otherwise it only shows up in the console.
()
| 9 | |
| 10 | /// Install a panic handler that prints stuff to the logs, otherwise it only shows up in the console. |
| 11 | fn init_panic_handler() { |
| 12 | let default_hook = std::panic::take_hook(); |
| 13 | |
| 14 | std::panic::set_hook(Box::new(move |info| { |
| 15 | // Do the default first, just in case logging fails too. |
| 16 | default_hook(info); |
| 17 | |
| 18 | // let stacktrace = std::backtrace::Backtrace::capture(); |
| 19 | let stacktrace = std::backtrace::Backtrace::force_capture(); |
| 20 | |
| 21 | subscriber::with_default(create_temporary_subscriber(), || { |
| 22 | tracing::error!( |
| 23 | stacktrace = stacktrace.to_string(), |
| 24 | info = info.to_string(), |
| 25 | "panicking" |
| 26 | ); |
| 27 | }); |
| 28 | |
| 29 | // We could exit the application if any of the background tokio tasks panic. |
| 30 | // However, they are not necessarily critical processes, the chain might still make progress. |
| 31 | // std::process::abort(); |
| 32 | })) |
| 33 | } |
| 34 | |
| 35 | #[tokio::main] |
| 36 | async fn main() { |
no test coverage detected