use flexi_logger;
use std;
use log::error;
use std::io::{Write, Error};
fn app_format(write: &mut dyn Write, now: &mut flexi_logger::DeferredNow, record: &flexi_logger::Record<'_>) -> Result<(), Error> {
write!(write, "{} [{}] {:<5} {} - {}",
now.now().format("%Y-%m-%d %H:%M:%S%.3f"),
record.module_path().unwrap_or("-"),
record.level(),
record.file().unwrap_or("-"),
&record.args())
}
pub fn init(spec: Option<&str>) {
flexi_logger::Logger::try_with_str(spec.unwrap_or("info")).unwrap()
.format(app_format)
.start().unwrap();
}
pub fn exit_with_error(msg: &str, code: i32) -> ! {
error!("Exiting: {}", msg);
std::process::exit(code);
}