Added logger macro
parent
4b22958a05
commit
f86106c9fa
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue