-
Notifications
You must be signed in to change notification settings - Fork 731
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
RotatingFileAppender #858
Comments
I transferred this to tokio-rs/tracing. Also, tagging @zekisherif, since it's related to the |
I am intending on creating a PR for this.
#[derive(Clone, Eq, PartialEq, Debug)]
enum RotationKind {
TimeBased(TimeBasedRotationKind),
SizeBased(u64-max size),
}
enum TimeBasedRotationKind {
Minutely,
Hourly,
Daily,
Never,
}
|
PR #828 will likely change the public api a bit so we'll have to keep this into consideration for any work done here.
Example trait definition which will look very similar to the current impl of pub(crate) trait InnerAppender {
fn write(&mut self, buf: &[u8]) -> io::Result<usize>; // Handles writing to the log file
fn refresh(&mut self); // Handles creating a new file to write to and modifying existing file names in the case of size based.
fn should_rollover(&self) -> bool // Determines whether a rollover should occur or not based of the rotation criteria.
} I don't envision many issues with what you are proposing outside of the changes to the api which are breaking changes. |
I don't think this a breaking change? The public
IMO, it would probably be simpler to just write #[derive(Clone, Eq, PartialEq, Debug)]
enum RotationKind {
Minutely,
Hourly,
Daily,
Never,
MaxSize(u64),
} Unless I'm missing something? What does the inner enum get us here? |
You're right. For some reason I thought |
but |
@hawkw but grouping the time base rotation will enable easier group handling. |
If you like, please do! |
also need to change this comment to explain the new design. Left a few unimplemented but the main skeleton is ready. Need to add documentation. Addressing tokio-rs#858 API Breaking changes: Rotation consts (MINUTELY, HOURLY, DAILY) are now functions.
So I just created a draft PR with the complete skeleton(and it does build). |
also need to change this comment to explain the new design. Left a few unimplemented but the main skeleton is ready. Need to add documentation. Addressing tokio-rs#858
also need to change this comment to explain the new design. Need to add documentation. Addressing tokio-rs#858
Motivation Adding an appender with max size per log file and max number of log files. Addressing tokio-rs#858 Solution Adding an appender very similar to the `RollingFileAppender`, that will base the rotation on size of log file and number of log files.
The PR is ready for review :-) |
actually we will need specify time and size at the same time. Whenever size limit or time limit exceed, the log will be rotated. That is the usual way log rotation being implemented in other languages and system. |
@brianjcj - we had a similar need, with rotation conditions based on date/time and/or size, also to rotate based on the local time of the system rather than UTC, and to use a "Debian-style" log rotation scheme where the current logfile always has the same name. Since this had some different design requirements than the RollingFileAppender here in tracing-appender, rather than add so many options/variants to RollingFileAppender here, we found it cleaner just to implement our own and then combine that with NonBlocking, which is working well. We were surprised there didn't seem to be another crate implementing such a thing (at least as far as we could find), so we've published this as the rolling-file crate. All feedback welcome. |
Until tracing became a necessity for me I loved to use flexi_logger with flexi_logger::Logger::with(LogSpecification::info())
.use_windows_line_ending()
.log_to_file(flexi_logger::FileSpec::default().directory("logs"))
.duplicate_to_stdout(flexi_logger::Duplicate::Info)
.append()
.rotate(
flexi_logger::Criterion::Size(100 * 1024_u64 * 1024_u64),
flexi_logger::Naming::Timestamps,
flexi_logger::Cleanup::KeepCompressedFiles(1000),
)
.cleanup_in_background_thread(true) This enables async file compression, as long as you keep a token alive. Before exiting the program Is something like this an option for the rolling appender? |
This patch adds size-based rotation to tracing-appender. In a constraint environment, we should be able to contain the logging size and period. Related issues: - tokio-rs#1940 - tokio-rs#858
This patch adds size-based rotation to tracing-appender. In a constraint environment, we should be able to contain the logging size and period. Related issues: - tokio-rs#1940 - tokio-rs#858
This patch adds size-based rotation to tracing-appender. In a constraint environment, we should be able to contain the logging size and period. Related issues: - tokio-rs#1940 - tokio-rs#858
This patch adds size-based rotation to tracing-appender. In a constraint environment, we should be able to contain the logging size and period. Related issues: - tokio-rs#1940 - tokio-rs#858
This patch adds size-based rotation to tracing-appender. In a constraint environment, we should be able to contain the logging size and period. Related issues: - tokio-rs#1940 - tokio-rs#858
This patch adds size-based rotation to tracing-appender. In a constraint environment, we should be able to contain the logging size and period. Related issues: - tokio-rs#1940 - tokio-rs#858
This patch adds size-based rotation to tracing-appender. In a constraint environment, we should be able to contain the logging size and period. Related issues: - tokio-rs#1940 - tokio-rs#858
This patch adds size-based rotation to tracing-appender. In a constraint environment, we should be able to contain the logging size and period. Related issues: - tokio-rs#1940 - tokio-rs#858
This patch adds size-based rotation to tracing-appender. In a constraint environment, we should be able to contain the logging size and period. Related issues: - tokio-rs#1940 - tokio-rs#858
This patch adds size-based rotation to tracing-appender. In a constraint environment, we should be able to contain the logging size and period. Related issues: - tokio-rs#1940 - tokio-rs#858
This patch adds size-based rotation to tracing-appender. In a constraint environment, we should be able to contain the logging size and period. Related issues: - tokio-rs#1940 - tokio-rs#858
This patch adds size-based rotation to tracing-appender. In a constraint environment, we should be able to contain the logging size and period. Related issues: - tokio-rs#1940 - tokio-rs#858
Is your feature request related to a problem? Please describe.
I want to supply logs to the application that I write by using
tracing
,tracing-subscriber
, andtracing-appender
, but it's crucial to enforce small log files and a boundary to the total size of all the logs.Small files - since its easier to read.
Total size - since disk space might be limited.
Describe the solution you'd like
I propose creating another
Rotation
that will be based on size instead of time.
this rotation will be a configuration of two parameters:
This rotation will create a new file every time the current file exceeds the allowed size and will bump all current old files indexes. In case the maximum number of files is reached it will delete the oldest file.
Describe alternatives you've considered
The current time-based rotation is not enough since it might vary a lot even in the apps.
Additional context
Python
RotatingFileHandler
The text was updated successfully, but these errors were encountered: