mod config;
pub use config::{LogConfig, LogError, _LOG_CONFIG};
#[doc(hidden)]
pub use time;
#[doc(hidden)]
#[macro_export]
macro_rules! _time {
() => {
$crate::time::now()
.strftime(unsafe { $crate::_LOG_CONFIG.get_date_format() })
.unwrap()
};
}
#[macro_export]
macro_rules! trace {
($($arg:tt)*) => {
if unsafe { $crate::_LOG_CONFIG.get_trace() } {
if unsafe { $crate::_LOG_CONFIG.get_color() } {
println!("[{}] \x1B[2;3m[TRACE]\x1B[0m {}", $crate::_time!(), format!($($arg)*));
} else {
println!("[{}] [TRACE] {}", $crate::_time!(), format!($($arg)*));
}
}
};
}
#[macro_export]
macro_rules! debug {
() => {
if unsafe { $crate::_LOG_CONFIG.get_debug() } {
if unsafe { $crate::_LOG_CONFIG.get_color() } {
println!("[{}] \x1B[36m[DEBUG]\x1B[0m [{}:{}]", $crate::_time!(), file!(), line!());
} else {
println!("[{}] [DEBUG] [{}:{}]", $crate::_time!(), file!(), line!());
}
}
};
($val:expr) => {
if unsafe { $crate::_LOG_CONFIG.get_debug() } {
if unsafe { $crate::_LOG_CONFIG.get_color() } {
println!("[{}] \x1B[36m[DEBUG]\x1B[0m [{}:{}]\n{:#?}", $crate::_time!(), file!(), line!(), $val);
} else {
println!("[{}] [DEBUG] [{}:{}]\n{:#?}", $crate::_time!(), file!(), line!(), $val);
}
}
};
($($arg:expr), *) => {
if unsafe { $crate::_LOG_CONFIG.get_debug() } {
if unsafe { $crate::_LOG_CONFIG.get_color() } {
print!("[{}] \x1B[36m[DEBUG]\x1B[0m [{}:{}]\n{}", $crate::_time!(), file!(), line!(), {
let mut content = String::new();
$(content += &format!("{:#?}\n", $arg);)*
content
});
} else {
print!("[{}] [DEBUG] [{}:{}]\n{}", $crate::_time!(), file!(), line!(), {
let mut content = String::new();
$(content += &format!("{:#?}\n", $arg);)*
content
});
}
}
};
}
#[macro_export]
macro_rules! info {
($($arg:tt)*) => {
if unsafe { $crate::_LOG_CONFIG.get_info() } {
if unsafe { $crate::_LOG_CONFIG.get_color() } {
println!("[{}] \x1B[32m[INFO ]\x1B[0m {}", $crate::_time!(), format!($($arg)*));
} else {
println!("[{}] [INFO ] {}", $crate::_time!(), format!($($arg)*));
}
}
};
}
#[macro_export]
macro_rules! warn {
($($arg:tt)*) => {
if unsafe { $crate::_LOG_CONFIG.get_warn() } {
if unsafe { $crate::_LOG_CONFIG.get_color() } {
println!("[{}] \x1B[4;33m[WARN ]\x1B[0m {}", $crate::_time!(), format!($($arg)*));
} else {
println!("[{}] [WARN ] {}", $crate::_time!(), format!($($arg)*));
}
}
};
}
#[macro_export]
macro_rules! error {
($($arg:tt)*) => {
if unsafe { $crate::_LOG_CONFIG.get_error() } {
if unsafe { $crate::_LOG_CONFIG.get_color() } {
eprintln!("[{}] \x1B[1;31m[ERROR]\x1B[0m {}", $crate::_time!(), format!($($arg)*));
} else {
eprintln!("[{}] [ERROR] {}", $crate::_time!(), format!($($arg)*));
}
}
};
}