36 lines
606 B
Rust
36 lines
606 B
Rust
|
|
#[derive(Debug, Default)]
|
||
|
|
pub struct Logger {
|
||
|
|
pub quiet: bool,
|
||
|
|
}
|
||
|
|
|
||
|
|
impl Logger {
|
||
|
|
pub fn info(&self, message: impl ToString) {
|
||
|
|
if self.quiet {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
println!("{}", message.to_string());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
#[macro_export]
|
||
|
|
macro_rules! log {
|
||
|
|
($logger:expr, $level:ident, $($args:tt)*) => {
|
||
|
|
$logger.$level(format!($($args)*));
|
||
|
|
};
|
||
|
|
($logger:expr, $($args:tt)*) => {
|
||
|
|
log!($logger, info, $($args)*);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
#[cfg(test)]
|
||
|
|
mod test {
|
||
|
|
use crate::logger::Logger;
|
||
|
|
|
||
|
|
#[test]
|
||
|
|
#[ignore]
|
||
|
|
fn syntax_test() {
|
||
|
|
let logger = Logger { quiet: false };
|
||
|
|
log!(logger, "Foo {}", "bar");
|
||
|
|
}
|
||
|
|
}
|