-
Notifications
You must be signed in to change notification settings - Fork 755
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
Size rolling #2904
base: master
Are you sure you want to change the base?
Size rolling #2904
Conversation
bf707aa
to
8ca4e2a
Compare
Hi @hawkw @davidbarsky @hds, What would it take to get this reviewed? Should I just close it since nobody will ever look at it? |
@x3ccd4828 I can look at this, but I'm currently very full up with family stuff, would you mind reminding me after the 25th of January? I'll be back at work then (and therefore at my computer) and will make some time to go through old PRs and issues. |
Tha is understandable, I will post here at the end of January |
8ca4e2a
to
90be4b4
Compare
90be4b4
to
65851cd
Compare
@hds I have rebased the branch would you be able to review it? |
/// # fn docs() { | ||
/// let appender = RollingFileAppender::builder() | ||
/// .rotation(Rotation::SIZE) // rotate log files when they reach a certain size | ||
/// .max_file_size(1024) // only the most recent 5 log files will be kept |
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.
Comment doesnt seem right, shouldn't this say something like // Will roll over once file reaches 1024 bytes
?
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.
thank you for catching that I fixed the comment
/// ``` | ||
/// | ||
/// This will result in a log file located at `/some/path/rolling.log`. | ||
pub fn size(directory: impl AsRef<Path>, file_name: impl AsRef<Path>) -> RollingFileAppender { |
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.
So in this doc i do not see a default file size thats used, i think would be handy to mention that?
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.
There is no default since it's an option. So if the user selects size but doesn't provide a size it will do nothing. Should I capture this behaviour in the doc files?
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.
I am not that experienced in Rust but i meant that from my understanding, these docs say
let appender = tracing_appender::rolling::size("/some/path", "rolling.log");
Which seems to me to be making a size rolling appender and passing it the path and log file name but there is no parameter for the size. Therefore i would expect a default size. If there is no default size and the size rollover wont work then i think its good to document that, otherwise a bit unclear how your supposed to use it or what you can expect.
@x3ccd4828 Could you update your branch with the latest official traceing-appenders? If i am not mistaken this branch is still on version 0.2.0? Thats at least what my toml lock file is indicating, i was on version 0.2.3 before and had tracing working in both console and file appending using the time rotation but when i use your branch, i get errors indicating that the file appender doesnt implement MakeWriter?
My code for tracing to the console and log file looks like this:
|
@JoelSatkas I rebased based on tracing master branch but for some reason master branch has tracing-appender at 0.2.0. |
I see. Thats okay and thank you for checking. I would love to have this feature in the project im working on but for now the time rollover will have to suffice. I hope this PR will be properly reviewed by the developers soon and thank you for contributing |
This patch adds size-based rotation to tracing-appender.
Closes #1940
Closes #858
cc @hawkw @IniterWorker @CfirTsabari @davidbarsky @CBenoit
There is another pull request (#2497) for this feature but I thought I would try a different approach.
Motivation
In a constrained environment, we should be able to constrain the logging size and period.
Solution
Maximum bytes per log file may be specified in the
max_file_size
function when building the appender. The option will only be used when selectingRotation::SIZE
.File size is checked every write and if the size is exceeded the log file is rolled over.
None of the other rotation types use sub-seconds in the logfile name but for size-based rotation, I used it since there could be a plethora of writes in a short period and this was the simple way to ensure filename uniqueness otherwise it would write to the same file even if the size was exceeded. This is a limitation since I tried to use the same methodology as the time-based rolling without rewriting the architecture.