#[cfg(feature = "logs")]
pub static LOG: std::sync::Once = std::sync::Once::new();
#[macro_export]
macro_rules! init_log {
() => {
$crate::log::LOG.call_once(|| {
let mut builder = simplelog::ConfigBuilder::new();
let result = builder.set_time_format_rfc2822().set_time_offset_to_local();
let config = if let Ok(builder) = result {
builder
} else {
result.unwrap_err()
}
.build();
_ = simplelog::CombinedLogger::init(vec![simplelog::TermLogger::new(
log::LevelFilter::Info,
config,
simplelog::TerminalMode::Mixed,
simplelog::ColorChoice::Auto,
)]);
});
};
}
#[macro_export]
macro_rules! info {
(target: $target:expr, $($arg:tt)+) => {
cfg_if::cfg_if! {
if #[cfg(feature = "logs")] {
$crate::init_log!();
log::log!(target: $target, log::Level::Info, $($arg)+)
}
}
};
($($arg:tt)+) => {
cfg_if::cfg_if! {
if #[cfg(feature = "logs")] {
$crate::init_log!();
log::log!(log::Level::Info, $($arg)+)
}
}
}
}
#[macro_export]
macro_rules! warn {
(target: $target:expr, $($arg:tt)+) => {
cfg_if::cfg_if! {
if #[cfg(feature = "logs")] {
$crate::init_log!();
log::log!(target: $target, log::Level::Warn, $($arg)+)
}
}
};
($($arg:tt)+) => {
cfg_if::cfg_if! {
if #[cfg(feature = "logs")] {
$crate::init_log!();
log::log!(log::Level::Warn, $($arg)+)
}
}
}
}
#[macro_export]
macro_rules! error {
(target: $target:expr, $($arg:tt)+) => {
cfg_if::cfg_if! {
if #[cfg(feature = "logs")] {
$crate::init_log!();
log::log!(target: $target, log::Level::Error, $($arg)+)
}
}
};
($($arg:tt)+) => {
cfg_if::cfg_if! {
if #[cfg(feature = "logs")] {
$crate::init_log!();
log::log!(log::Level::Error, $($arg)+)
}
}
}
}