Skip to content

Commit f2b2665

Browse files
vschwaberowextrawurst
authored andcommitted
Addresses TODO with macro log_eprintln!
1 parent 5906a27 commit f2b2665

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/main.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -327,23 +327,27 @@ fn start_terminal<W: Write>(
327327
Ok(terminal)
328328
}
329329

330+
// do log::error! and eprintln! in one line, pass sting, error and backtrace
331+
macro_rules! log_eprintln {
332+
($string:expr, $e:expr, $bt:expr) => {
333+
log::error!($string, $e, $bt);
334+
eprintln!($string, $e, $bt);
335+
};
336+
}
337+
330338
fn set_panic_handlers() -> Result<()> {
331339
// regular panic handler
332340
panic::set_hook(Box::new(|e| {
333341
let backtrace = Backtrace::new();
334-
//TODO: create macro to do both in one
335-
log::error!("panic: {:?}\ntrace:\n{:?}", e, backtrace);
336-
eprintln!("panic: {:?}\ntrace:\n{:?}", e, backtrace);
342+
log_eprintln!("panic: {:?}\ntrace:\n{:?}", e, backtrace);
337343
shutdown_terminal();
338344
}));
339345

340346
// global threadpool
341347
rayon_core::ThreadPoolBuilder::new()
342348
.panic_handler(|e| {
343349
let backtrace = Backtrace::new();
344-
//TODO: create macro to do both in one
345-
log::error!("panic: {:?}\ntrace:\n{:?}", e, backtrace);
346-
eprintln!("panic: {:?}\ntrace:\n{:?}", e, backtrace);
350+
log_eprintln!("panic: {:?}\ntrace:\n{:?}", e, backtrace);
347351
shutdown_terminal();
348352
process::abort();
349353
})

0 commit comments

Comments
 (0)