diff --git a/tracing-appender/Cargo.toml b/tracing-appender/Cargo.toml index 5546f2fee9..49a50a6daa 100644 --- a/tracing-appender/Cargo.toml +++ b/tracing-appender/Cargo.toml @@ -20,6 +20,10 @@ keywords = ["logging", "tracing", "file-appender", "non-blocking-writer"] edition = "2018" rust-version = "1.53.0" +[features] +# Enables support for rolling file using local time +local-time = ["time/local-offset"] + [dependencies] crossbeam-channel = "0.5.5" time = { version = "0.3.2", default-features = false, features = ["formatting", "parsing"] } diff --git a/tracing-appender/src/lib.rs b/tracing-appender/src/lib.rs index fad49fe677..00493bd961 100644 --- a/tracing-appender/src/lib.rs +++ b/tracing-appender/src/lib.rs @@ -120,6 +120,10 @@ //! # } //! ``` //! +//! ## Feature Flags +//! +//! - `local-time`: Enables support for rolling file using local time +//! //! ## Supported Rust Versions //! //! `tracing-appender` is built against the latest stable release. The minimum supported diff --git a/tracing-appender/src/rolling.rs b/tracing-appender/src/rolling.rs index 3c0321f04e..b0dc88c6d4 100644 --- a/tracing-appender/src/rolling.rs +++ b/tracing-appender/src/rolling.rs @@ -209,12 +209,19 @@ impl RollingFileAppender { }) } + #[cfg(test)] + #[inline] + fn now(&self) -> OffsetDateTime { + (self.now)() + } + + #[cfg(not(test))] #[inline] fn now(&self) -> OffsetDateTime { - #[cfg(test)] - return (self.now)(); + #[cfg(feature = "local-time")] + return OffsetDateTime::now_local().expect("Unable to get local time"); - #[cfg(not(test))] + #[cfg(not(feature = "local-time"))] OffsetDateTime::now_utc() } }