From f09e50592fa6089433c89d466db4fa6f7966fd0b Mon Sep 17 00:00:00 2001 From: Jesse Szwedko Date: Wed, 3 Nov 2021 12:12:30 -0600 Subject: [PATCH] Avoid timezone look-ups on Unix given they always fail Due to https://github.com/time-rs/time/issues/380 Signed-off-by: Jesse Szwedko --- src/format.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/format.rs b/src/format.rs index 90991e7..83a1f48 100644 --- a/src/format.rs +++ b/src/format.rs @@ -75,7 +75,7 @@ impl LogFormat for Formatter3164 { w, "<{}>{} {} {}[{}]: {}", encode_priority(severity, self.facility), - time::OffsetDateTime::now_local() + now_local() .map(|timestamp| timestamp.format(&format).unwrap()) .unwrap(), hostname, @@ -89,7 +89,7 @@ impl LogFormat for Formatter3164 { w, "<{}>{} {}[{}]: {}", encode_priority(severity, self.facility), - time::OffsetDateTime::now_local() + now_local() .map(|timestamp| timestamp.format(&format).unwrap()) .unwrap(), self.process, @@ -165,3 +165,15 @@ impl LogFormat<(i32, StructuredData, T)> for Formatter5424 { fn encode_priority(severity: Severity, facility: Facility) -> Priority { facility as u8 | severity as u8 } + +#[cfg(unix)] +// On unix platforms, time::OffsetDateTime::now_local always returns an error so use UTC instead +// https://github.com/time-rs/time/issues/380 +fn now_local() -> std::result::Result { + Ok(time::OffsetDateTime::now_utc()) +} + +#[cfg(not(unix))] +fn now_local() -> std::result::Result { + time::OffsetDateTime::now_local() +}