You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I noticed that while the tracing_appender crate rotates file based on the date, it does not (I think) support file rotation based on the file size.
The most backwards compatible implementation I can think of is adding a size: u64 field to the tracing_appender::rolling::Rotation struct. Then, logic would be updated in tracing_appender::rolling::Inner::should_rollover to check for file size if that criteria is set.
Another idea could be to create an new trait called Criteria which exposes the method fn should_rollover(inner: &Inner) -> bool. We could then parameterize the Inner struct with a generic bounded to that trait, and then implement should_rollever for the various rollover types which implement Criteria.
Something like
traitCriteria{fnshould_rollover(inner:Inner) -> bool}#[derive(Debug)]structInner<C:Critera>{log_directory:PathBuf,log_filename_prefix:Option<String>,log_filename_suffix:Option<String>,date_format:Vec<format_description::FormatItem<'static>>,rotation:C,next_date:AtomicUsize,max_files:Option<usize>,}impl<C:Criteria>forInner<Criteria>{// Keep function defintions as is/// Keep this signature the same to minimize code change/// but within the method body...fnshould_rollover(&self,date:OffsetDateTime) -> Option<usize>{let should_roll = self.rotation::should_rollover(self);// Convert to Option<usize>}}enumTemporalRotationPolicy{Daily,Monthly,}implCriteriaforTemporalRotationPolicy{fnshould_rollover(inner:Inner) -> bool{/// get current time etc, and determine if we should rollover}}// Similarly define StorageRotationPolicy and implement Criteria for it
The above solution could prevent a runtime check in should_rollover by allowing types such TemporalRotationPolicy (which already exists in the form of the RotationKind enum) and StorageRotationPolicy to implement their version of should_rollover.
I am sure this could be improved. I am new to Rust and apologize in advance. I am interested in learning the best approach.
If there is interest in this feature, I can try to make a pull request.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi, I noticed that while the
tracing_appender
crate rotates file based on the date, it does not (I think) support file rotation based on the file size.The most backwards compatible implementation I can think of is adding a
size: u64
field to thetracing_appender::rolling::Rotation
struct. Then, logic would be updated intracing_appender::rolling::Inner::should_rollover
to check for file size if that criteria is set.Another idea could be to create an new trait called
Criteria
which exposes the methodfn should_rollover(inner: &Inner) -> bool
. We could then parameterize the Inner struct with a generic bounded to that trait, and then implementshould_rollever
for the various rollover types which implementCriteria
.Something like
The above solution could prevent a runtime check in
should_rollover
by allowing types suchTemporalRotationPolicy
(which already exists in the form of theRotationKind
enum) and StorageRotationPolicy to implement their version ofshould_rollover
.I am sure this could be improved. I am new to Rust and apologize in advance. I am interested in learning the best approach.
If there is interest in this feature, I can try to make a pull request.
Beta Was this translation helpful? Give feedback.
All reactions