2021-04-09 00:22:17 +00:00
|
|
|
use std::io::Write;
|
|
|
|
|
2021-12-21 00:14:12 +00:00
|
|
|
use log::Level;
|
|
|
|
use chrono::Local;
|
|
|
|
|
|
|
|
pub fn configure_logger(base_level: Level) -> () {
|
|
|
|
let actix_level = match base_level {
|
|
|
|
Level::Info => Level::Warn,
|
|
|
|
other_level => other_level,
|
|
|
|
};
|
2021-04-09 00:22:17 +00:00
|
|
|
env_logger::Builder::new()
|
|
|
|
.format(|buf, record| {
|
|
|
|
writeln!(buf,
|
|
|
|
"{} {} [{}] {}",
|
|
|
|
Local::now().format("%Y-%m-%dT%H:%M:%S"),
|
|
|
|
record.target(),
|
|
|
|
record.level(),
|
|
|
|
record.args(),
|
|
|
|
)
|
|
|
|
})
|
2021-12-21 00:14:12 +00:00
|
|
|
.filter_level(base_level.to_level_filter())
|
|
|
|
.filter_module("actix_web::middleware::logger", actix_level.to_level_filter())
|
2021-04-09 00:22:17 +00:00
|
|
|
.init();
|
|
|
|
}
|