tracing
tracing copied to clipboard
new feature: keep only the last N log files in rotation
Motivation
tracing-appender does not have Rotation based on size yet.
Also, it doesn't have the feature of keeping the most recent N log files
I believe the second feature is more easy to implement, and also will partially solve the Rotation based on size problem. Because people may choose hourly or daily rotation based on their needs, and put an extra boundary of keep the last 5 files for example. Of course it won't handle all the edge cases for Rotation based on size. But it will cover most of the scenarios. And also, it is a good feature to have on its own :)
Solution
Introduce another field called keep_last: Option<usize> to the Inner of RollingFileAppender struct.
I managed to did not touch any of the existing functions, so it WON'T BE A BREAKING CHANGE. Yay :)
The solution is, whenever the rotation should happen, the refresh_writer() is called. So I embed the following logic into that function:
1- check the log folder and detect the log files
2- if there are more log files than the last_keep amount
3- store the filenames in a vector, and sort them by their dates (dates are already present in the filename)
4- keep deleting the oldest ones, till we have desired amount of log files in the log folder
Is related to #858 and #1940
There is one test failing :/
i want to make a few additional notes, but since i'm packing for my move this weekend, it might be a day or two. sorry!
Any update on this?
I'm willing to make further updates if necessary :)
Sorry, it's been a busy month. Do you mind if I make commits directly to your branch/fork for the changes that I think we need? Since I believe this approach works for you, I'll also open a branch that targets the master branch—it'll make the subsequent branch maintenance on our side easier.
Of course, no worries!
Any update on this? :)
What happened to this PR? GitHub says it's merged, but it's not as far as I can tell

Because unfortunately there were no responses from the tokio team, I decided to use the fork for my project, and thus synced the fork. Weird that it says merged. Let me re-open the PR, maybe we can get some attention :)
New one is here: #2284