mirror of
https://github.com/tokio-rs/tracing.git
synced 2025-09-27 04:50:58 +00:00
appender: Add fallback to file creation date (#3000)
When using the linux-musl target for rust, the file creation time cannot be retrieved, as the current version does not support it yet ( This will be fixed with [0]). In the meantime, we parse the datetime from the filename and use that as a fallback. Fixes: #2999 [0]: https://github.com/rust-lang/rust/pull/125692
This commit is contained in:
parent
c036318aa3
commit
20f5b3d8ba
@ -34,7 +34,7 @@ use std::{
|
||||
path::{Path, PathBuf},
|
||||
sync::atomic::{AtomicUsize, Ordering},
|
||||
};
|
||||
use time::{format_description, Date, Duration, OffsetDateTime, Time};
|
||||
use time::{format_description, Date, Duration, OffsetDateTime, PrimitiveDateTime, Time};
|
||||
|
||||
mod builder;
|
||||
pub use builder::{Builder, InitError};
|
||||
@ -676,7 +676,24 @@ impl Inner {
|
||||
return None;
|
||||
}
|
||||
|
||||
let created = metadata.created().ok()?;
|
||||
let created = metadata.created().ok().or_else(|| {
|
||||
let mut datetime = filename;
|
||||
if let Some(prefix) = &self.log_filename_prefix {
|
||||
datetime = datetime.strip_prefix(prefix)?;
|
||||
datetime = datetime.strip_prefix('.')?;
|
||||
}
|
||||
if let Some(suffix) = &self.log_filename_suffix {
|
||||
datetime = datetime.strip_suffix(suffix)?;
|
||||
datetime = datetime.strip_suffix('.')?;
|
||||
}
|
||||
|
||||
Some(
|
||||
PrimitiveDateTime::parse(datetime, &self.date_format)
|
||||
.ok()?
|
||||
.assume_utc()
|
||||
.into(),
|
||||
)
|
||||
})?;
|
||||
Some((entry, created))
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
|
Loading…
x
Reference in New Issue
Block a user