Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tracing-appender/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
4 changes: 4 additions & 0 deletions tracing-appender/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions tracing-appender/src/rolling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down