From f86106c9fa2335e1795d5c8b35c8663c7d723fe6 Mon Sep 17 00:00:00 2001 From: Ayrton Chilibeck Date: Mon, 15 Jan 2024 01:20:50 -0700 Subject: [PATCH] Added logger macro --- src/util/logger.rs | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/util/logger.rs b/src/util/logger.rs index e3247d4..c544502 100644 --- a/src/util/logger.rs +++ b/src/util/logger.rs @@ -1,13 +1,23 @@ -fn l1_log(verbosity: u8, message: &str) { - if verbosity > 0 { - println!("{}", message); - } +// prints output to the stderr if the verbosity is +// greater than or equal to the logging level of the +// notification. +macro_rules! log { + // NOTE: this uses a variadic argument system + // copied from the std::fmt eprintln! macro + // see the appropriate documentation + ($l:expr, $v:expr, $($arg:tt)*) => {{ + if $v >= $l { + eprintln!($($arg)*); + } + }}; } -fn l2_log(verbosity: u8, message: &str) { - if verbosity > 1 { - println!("{}", message); +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_name() { + log!(1, 1, "this is a {}", "test"); } } - -//TODO unit test, but these are trivial