Added logger macro
parent
4b22958a05
commit
f86106c9fa
|
@ -1,13 +1,23 @@
|
||||||
fn l1_log(verbosity: u8, message: &str) {
|
// prints output to the stderr if the verbosity is
|
||||||
if verbosity > 0 {
|
// greater than or equal to the logging level of the
|
||||||
println!("{}", message);
|
// 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) {
|
#[cfg(test)]
|
||||||
if verbosity > 1 {
|
mod tests {
|
||||||
println!("{}", message);
|
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