#![allow(dead_code)]
#![allow(unused_macros)]
pub(crate) static LOGGING_INIT: std::sync::Once = std::sync::Once::new();
macro_rules! debug {
($($t:tt)+) => {
#[cfg(any(test, feature = "tracing", feature = "prod-logging"))]
tracing::debug!($($t)+);
};
}
macro_rules! trace {
($($t:tt)+) => {
#[cfg(any(test, feature = "tracing", feature = "prod-logging"))]
tracing::trace!($($t)+);
};
}
macro_rules! enable_logging {
() => {{
LOGGING_INIT.call_once(|| {
let subscriber = ::tracing_subscriber::FmtSubscriber::builder()
.with_env_filter("trace")
.with_writer(std::io::stdout)
.finish();
tracing::subscriber::set_global_default(subscriber).expect("failed to enable logging");
});
}};
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_logging() {
enable_logging!();
debug!("This is a debug message in test.");
trace!("This is a trace message in test.");
assert_eq!(2 + 2, 4);
}
}