libpcode/
logger.rs

1pub trait Logger {
2    fn should_log(&self) -> bool;
3    fn depth(&self) -> usize;
4    fn inc_depth(&mut self);
5    fn dec_depth(&mut self);
6}
7
8#[macro_export]
9macro_rules! log {
10    ($context:expr, $fmt:expr) => {
11        if $context.should_log() {
12            print!("{}", " ".repeat($context.depth() * 3));
13            println!($fmt);
14        }
15    };
16    ($context:expr, $fmt:expr, $($arg:tt)*) => {
17        if $context.should_log() {
18            print!("{}", " ".repeat($context.depth() * 3));
19            println!($fmt, $($arg)*);
20        }
21    };
22}