-
Notifications
You must be signed in to change notification settings - Fork 20
Description
File-rotate has existed for 6 years now, it's about time we create a version 1.0.
This is an RFC to address shortcomings of the current library and to improve upon them. Version 1.0 will be a breaking change.
Proposed Changes
Together with @Ploppz, we propose the following changes.
User-definable Rotation Schemes
The file rotation method must be user-definable to support use-cases that are beyond the scope of this library to support natively (#32, #27). file-rotate will provide a set of implementations for common cases (integer suffixes and timestamp suffixes). To accomplish this, we define a trait Rotator:
trait Rotator {
/// Called when a limit has been exceeded, or rotation is manually called. Takes the current file, and returns a potentially new file to start writing to.
/// After this call, any content limits are reset, even if we decide to not rotate, and instead write to the same file.
fn rotate(&mut self, current: File) -> File;
}With this trait we can instantiate FileRotate with an implementation of Rotator. The Rotator decides what suffix (#31) (if any) to use for the new file, to delete or overwrite the old file, or to run a post-compression algorithm on it (#5).
This method allows anyone to implement whatever is desired; one such case is setting file permissions for a specific OS.
User-definable Rotation Triggers
Currently, the library exposes fixed ContentLimits. In some cases, one might be interested in using available disk space or other, more complex scenarios. To support these cases, we define a trait.
trait Trigger {
/// Decides whether to trigger a rotation, returning.
fn trigger(&mut self, bytes: &[u8]) -> Action;
}trigger returns an Action, an enum.
enum Action {
Rotate { consumed: usize }, /// `consumed` is the amount of bytes to consume from the current buffer given to `trigger` before rotation, if it is less than `bytes.len()` in `trigger`, the remaining bytes will be consumed after `rotate`.
None /// Do not rotate, write all bytes to output file.
}For this trait, the library will provide the current ContentLimits. If common cases arise, they can be added to this crate.
RFC
We will have an open comment period to collect concerns and criticisms of this design.
@LinAGKar @ramyak-mehra @mbiggio @michalfita @Ploppz @craigdub @proski @PhilVince96 @jsdanielh @tuxmark5 @wizzardx @jb-alvarado @happybeing @vbmade2000 @rohitjoshi