Addresses TODO with macro log_eprintln!

This commit is contained in:
Volker Schwaberow 2022-09-11 10:42:19 +02:00 committed by extrawurst
parent 5906a2789d
commit f2b2665c78

View File

@ -327,13 +327,19 @@ fn start_terminal<W: Write>(
Ok(terminal)
}
// do log::error! and eprintln! in one line, pass sting, error and backtrace
macro_rules! log_eprintln {
($string:expr, $e:expr, $bt:expr) => {
log::error!($string, $e, $bt);
eprintln!($string, $e, $bt);
};
}
fn set_panic_handlers() -> Result<()> {
// regular panic handler
panic::set_hook(Box::new(|e| {
let backtrace = Backtrace::new();
//TODO: create macro to do both in one
log::error!("panic: {:?}\ntrace:\n{:?}", e, backtrace);
eprintln!("panic: {:?}\ntrace:\n{:?}", e, backtrace);
log_eprintln!("panic: {:?}\ntrace:\n{:?}", e, backtrace);
shutdown_terminal();
}));
@ -341,9 +347,7 @@ fn set_panic_handlers() -> Result<()> {
rayon_core::ThreadPoolBuilder::new()
.panic_handler(|e| {
let backtrace = Backtrace::new();
//TODO: create macro to do both in one
log::error!("panic: {:?}\ntrace:\n{:?}", e, backtrace);
eprintln!("panic: {:?}\ntrace:\n{:?}", e, backtrace);
log_eprintln!("panic: {:?}\ntrace:\n{:?}", e, backtrace);
shutdown_terminal();
process::abort();
})