Skip to content

Commit 3f520c1

Browse files
committed
tracing-appender: support rolling file using local time
1 parent bdbaf80 commit 3f520c1

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

tracing-appender/Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ keywords = ["logging", "tracing", "file-appender", "non-blocking-writer"]
2020
edition = "2018"
2121
rust-version = "1.53.0"
2222

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

tracing-appender/src/rolling.rs

+10-3
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().unwrap_or_else(|_| OffsetDateTime::now_utc());
216223

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

0 commit comments

Comments
 (0)