better logging handling

This commit is contained in:
2024-04-16 15:03:10 +02:00
parent 2480ee6e06
commit e0c583cca8
3 changed files with 16 additions and 5 deletions

View File

@ -1,17 +1,20 @@
pub fn setup_logger() -> Result<(), fern::InitError> {
fern::Dispatch::new()
.format(|out, message, record| {
.format(move |out, message, record| {
out.finish(format_args!(
"{}[{}][{}] {}",
chrono::Local::now().format("[%Y-%m-%d][%H:%M:%S]"),
std::thread::current().name().expect("unnamed_thread"),
"[{}][{}][{}] {}",
humantime::format_rfc3339_millis(std::time::SystemTime::now()),
std::thread::current().name().unwrap_or("unnamed_thread"),
record.level(),
message
))
})
.level(log::LevelFilter::Debug)
.chain(std::io::stdout())
.chain(fern::log_file("output.log")?)
.chain(fern::log_file(format!(
"output_{}.log",
humantime::format_rfc3339_seconds(std::time::SystemTime::now())
))?)
.apply()?;
Ok(())
}