diff --git a/Cargo.lock b/Cargo.lock index 05ceabe..b85f20f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -239,6 +239,12 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + [[package]] name = "iana-time-zone" version = "0.1.60" @@ -376,6 +382,7 @@ dependencies = [ "chrono", "derive-new", "fern", + "humantime", "lazy_static", "log", "num_enum", diff --git a/Cargo.toml b/Cargo.toml index 5a74807..a970584 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ fern = "0.6" chrono = "0.4" log = "0.4" lazy_static = "1" +humantime = "2" strum = { version = "0.26", features = ["derive"] } thiserror = "1" derive-new = "0.6" diff --git a/src/logger.rs b/src/logger.rs index 5e7163c..8c50ea1 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -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(()) }