-
Notifications
You must be signed in to change notification settings - Fork 838
appender: Add fallback to file creation date #3000
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
You may need to handle the prefix and suffix before parsing the date (a reverse function of tracing/tracing-appender/src/rolling.rs Lines 551 to 569 in c6bedbe
|
2723cf7 to
e683054
Compare
|
Oh, yeah, you're right. Thanks for the heads up, updated it now. Extracted the the datetime from the prefix/suffix, then converted to PrimitiveDateTime (because OffsetDateTime also takes a offset), then just assume it's utc (this is fine, because we also do this when writing AFAIK). |
|
The prefix or suffix can also contain a dot. |
e683054 to
3c23950
Compare
|
Damn, forgot about that. Should work now! |
3c23950 to
1cbad61
Compare
|
Third time's the charm :) |
|
|
|
What do you mean exactly, could you paste an example? If the logfile prefix given is not actually the prefix in the filename, we will get a wrong date string and the parsing will fail, but this is intended. |
|
I think you could have suffix |
|
Oof, right. I could reverse the suffix and the whole filename string and then search through? Like that I would always get the first substring from behind. AFAIK rust doesn't have a function to make it more convention ... |
|
Wouldn't |
1cbad61 to
578fcc8
Compare
|
Hi! what's the status of this PR? Looks like it addressed all the review comments, is it getting blocked for some reason? We'd love to have this fix to avoid using a fork of |
|
@davidbarsky friendly ping :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it'd be a fix for our use case and save us having to implement our own file rolling. Is there anything else we can do to help get this merged?
ed09753 to
6064a76
Compare
|
not work when rotation is set to Rotation::DAILY, PrimitiveDateTime::parse(datetime, &self.date_format) return None. PrimitiveDateTime can not parse a str without time part. let created:Option<SystemTime> = match self.rotation {
Rotation::DAILY => {
let day =Date::parse(datetime, &self.date_format).ok()?;
Some(PrimitiveDateTime::new(day, Time::MIDNIGHT).assume_utc().into())
},
_ => {
Some(PrimitiveDateTime::parse(datetime, &self.date_format)
.ok()?
.assume_utc().into())
}
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems sensible.
6064a76 to
4b22c27
Compare
|
Test failure unrelated (also happens on |
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: tokio-rs#2999 [0]: rust-lang/rust#125692
9364588 to
8635ea3
Compare
The necessary patch was merged[1] now, thanks to Jonas. We still need the patch section since we don't have a release with the patch. [1]: tokio-rs/tracing#3000
The necessary patch was merged[1] now, thanks to Jonas. We still need the patch section since we don't have a release with the patch. [1]: tokio-rs/tracing#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 1). In the meantime, we parse the datetime from the filename and use that as a fallback.
Fixes: #2999
Footnotes
https://github.com/rust-lang/rust/pull/125692 ↩