Skip to content

Commit b0689e9

Browse files
dan-onlinemessense
andcommitted
feat(tracing-appender): add support for rolling file using local time feature
Co-authored-by: messense <[email protected]>
1 parent dfc2c8b commit b0689e9

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

tracing-appender/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ keywords = ["logging", "tracing", "file-appender", "non-blocking-writer"]
2020
edition = "2018"
2121
rust-version = "1.53.0"
2222

23+
[features]
24+
# Enables support for rolling file using local time
25+
local-time = ["time/local-offset"]
26+
2327
[dependencies]
2428
crossbeam-channel = "0.5.5"
2529
time = { version = "0.3.2", default-features = false, features = ["formatting", "parsing"] }

tracing-appender/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@
121121
//! # }
122122
//! ```
123123
//!
124+
//! ## Feature Flags
125+
//!
126+
//! - `local-time`: Enables support for rolling file using local time
127+
//!
124128
//! ## Supported Rust Versions
125129
//!
126130
//! `tracing-appender` is built against the latest stable release. The minimum supported

tracing-appender/src/rolling.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,19 @@ impl RollingFileAppender {
209209
})
210210
}
211211

212+
#[cfg(test)]
213+
#[inline]
214+
fn now(&self) -> OffsetDateTime {
215+
(self.now)()
216+
}
217+
218+
#[cfg(not(test))]
212219
#[inline]
213220
fn now(&self) -> OffsetDateTime {
214-
#[cfg(test)]
215-
return (self.now)();
221+
#[cfg(feature = "local-time")]
222+
return OffsetDateTime::now_local().expect("Unable to get local time");
216223

217-
#[cfg(not(test))]
224+
#[cfg(not(feature = "local-time"))]
218225
OffsetDateTime::now_utc()
219226
}
220227
}

0 commit comments

Comments
 (0)