diff --git a/Cargo.lock b/Cargo.lock index 56b66539ce5..87f6a82bf43 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11558,6 +11558,7 @@ version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "004cbc98f30fa233c61a38bc77e96a9106e65c88f2d3bef182ae952027e5753d" dependencies = [ + "itoa 1.0.1", "libc", "num_threads", ] diff --git a/relays/utils/Cargo.toml b/relays/utils/Cargo.toml index 7ca5e77cd95..7996ba72f87 100644 --- a/relays/utils/Cargo.toml +++ b/relays/utils/Cargo.toml @@ -19,7 +19,7 @@ log = "0.4.11" num-traits = "0.2" serde_json = "1.0" sysinfo = "0.15" -time = "0.3" +time = { version = "0.3", features = ["formatting", "local-offset", "std"] } thiserror = "1.0.26" # Bridge dependencies diff --git a/relays/utils/src/initialize.rs b/relays/utils/src/initialize.rs index 8c13a4d61cb..ad69a766e62 100644 --- a/relays/utils/src/initialize.rs +++ b/relays/utils/src/initialize.rs @@ -29,15 +29,21 @@ pub fn initialize_relay() { /// Initialize Relay logger instance. pub fn initialize_logger(with_timestamp: bool) { + let format = time::format_description::parse( + "[year]-[month]-[day] \ + [hour repr:24]:[minute]:[second] [offset_hour sign:mandatory]", + ) + .expect("static format string is valid"); + let mut builder = env_logger::Builder::new(); builder.filter_level(log::LevelFilter::Warn); builder.filter_module("bridge", log::LevelFilter::Info); builder.parse_default_env(); if with_timestamp { builder.format(move |buf, record| { - let timestamp = time::OffsetDateTime::try_now_local() - .unwrap_or_else(|_| time::OffsetDateTime::now_utc()) - .format("%Y-%m-%d %H:%M:%S %z"); + let timestamp = time::OffsetDateTime::now_local() + .unwrap_or_else(|_| time::OffsetDateTime::now_utc()); + let timestamp = timestamp.format(&format).unwrap_or_else(|_| timestamp.to_string()); let log_level = color_level(record.level()); let log_target = color_target(record.target());