Diffstat (limited to 'src/logger.rs')
1 file changed, 11 insertions(+), 8 deletions(-)
@@ -6,7 +6,18 @@
use std::path::PathBuf;
use std::{env, fs};
use crate::tui::Tui;
pub fn init() -> Result<()> {
let default_hook = panic::take_hook();
panic::set_hook(Box::new(move |panic_info| {
Tui::restore_terminal();
error!("APPLICATION PANIC: {}", panic_info);
logger().flush();
default_hook(panic_info);
}));
let level = match env::var("NMRS_LOG")
.unwrap_or_default()
.to_lowercase()
@@ -23,14 +34,6 @@
let log_file = File::create(&log_path).expect("Failed to create log file.");
CombinedLogger::init(vec![WriteLogger::new(level, Config::default(), log_file)]).unwrap();
let default_hook = panic::take_hook();
panic::set_hook(Box::new(move |panic_info| {
error!("APPLICATION PANIC: {}", panic_info);
logger().flush();
default_hook(panic_info);
}));
info!("Logger initialized successfully at {:?}", log_path);
Ok(())