From 4db8a3c200345d67ef178308a11d253a112d6304 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Mon, 3 Feb 2025 09:34:56 +1300 Subject: Implement a fatal log level The error log level now reports recoverable errors, with the fatal log level being reserved for unrecoverable errors where the program should immediately terminate. --- src/lib.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 7af1f20..5777fcd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -70,6 +70,22 @@ pub fn get_log_level() -> LogLevel { $crate::NORMAL, ); } + }}; +} + +#[macro_export] macro_rules! fatal { + ($($tokens:tt)*) => {{ + if *$crate::LOG_LEVEL.lock().unwrap() <= { $crate::LogLevel::Fatal } { + eprint!("{}{}[FATAL]{}: ", + $crate::BOLD, + $crate::RED, + $crate::WHITE, + ); + eprint!($($tokens)*); + eprintln!("{}", + $crate::NORMAL, + ); + } std::process::exit(1); }}; } -- cgit v1.2.3-70-g09d2