diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 16 | ||||
-rw-r--r-- | src/log_level.rs | 12 |
2 files changed, 27 insertions, 1 deletions
@@ -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); }}; } diff --git a/src/log_level.rs b/src/log_level.rs index 6c84cb0..9293efc 100644 --- a/src/log_level.rs +++ b/src/log_level.rs @@ -7,8 +7,10 @@ pub enum LogLevel { Info, /// Report recoverable issues. Warn, - /// Report unrecoverable errors and quit. + /// Report recoverable process errors. Error, + /// Report unrecoverable application errors and quit. + Fatal, } impl PartialOrd for LogLevel { @@ -24,14 +26,22 @@ impl Ord for LogLevel { (Info , Info ) => Ordering::Equal, (Info , Warn ) => Ordering::Less, (Info , Error) => Ordering::Less, + (Info , Fatal) => Ordering::Less, (Warn , Info ) => Ordering::Greater, (Warn , Warn ) => Ordering::Equal, (Warn , Error) => Ordering::Less, + (Warn , Fatal) => Ordering::Less, (Error , Info ) => Ordering::Greater, (Error , Warn ) => Ordering::Greater, (Error , Error) => Ordering::Equal, + (Error , Fatal) => Ordering::Less, + + (Fatal , Info ) => Ordering::Greater, + (Fatal , Warn ) => Ordering::Greater, + (Fatal , Error) => Ordering::Greater, + (Fatal , Fatal) => Ordering::Equal, } } } |