From f2b2665c787bda4d5dd3b04a5d2218d21b11489a Mon Sep 17 00:00:00 2001 From: Volker Schwaberow Date: Sun, 11 Sep 2022 10:42:19 +0200 Subject: [PATCH] Addresses TODO with macro log_eprintln! --- src/main.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0392bbf8..3cc81d08 100644 --- a/src/main.rs +++ b/src/main.rs @@ -327,13 +327,19 @@ fn start_terminal( 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(); })