Added logger macro

pull/5/head
Ayrton Chilibeck 2024-01-15 01:20:50 -07:00
parent 4b22958a05
commit f86106c9fa
Signed by: ayrton
GPG Key ID: BAE24A03DCBF160D
1 changed files with 19 additions and 9 deletions

View File

@ -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