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