My personal project and infrastructure archive
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
nomicon/apps/unionbot/src/log_util.rs

36 lines
821 B

#[macro_export]
macro_rules! fatal {
() => {
error!("Unknown failure!");
std::process::exit(2)
};
($($arg:tt)*) => ({
error!($($arg)*);
std::process::exit(2)
})
}
use colored::*;
use env_logger::Builder;
use log::Level;
use std::io::Write;
pub fn initialise() {
let mut b = Builder::from_default_env();
b.format(|buf, record| {
let lvl = record.level().to_string();
write!(
buf,
"[{}]: {}\n",
match record.level() {
Level::Error => lvl.red(),
Level::Warn => lvl.yellow(),
Level::Info => lvl.green(),
Level::Debug => lvl.purple(),
Level::Trace => lvl.cyan(),
},
record.args()
)
})
.init();
}