tokio-rs / tracing

Application level tracing for Rust.
https://tracing.rs
MIT License
5.42k stars 710 forks source link

tracing-appender: Custom rotation duration #778

Open Karrq opened 4 years ago

Karrq commented 4 years ago

Feature Request

Crates

tracing-appender

Motivation

Allow custom rotation timings for logs. Right now only 3 types are available: hourly, daily and never. This is far too coarse to provide efficient logging. My particular use case, is a "watcher" application that monitors something every X ms (configured at the start), it would be incredibly nice if I could specify X ms (for example) per rotation, effectively making each log be one run of the "watch"

Proposal

Add another enum constructor with a std::time::Duration and do calculations based on that instead of fixed timesteps. (chrono's DateTime<Tz> implements Add<Duration> for DateTime<Tz>, thererfore it's pretty direct.

This right now it's only associated const items that resolve to a variant of the enum Roation.

round_date needs to be changed to account for this, one way could be assuming the custom duration to be a divisor of the unrounded_date, and thus discarding the remainder, calculations should be done using nanoseconds for as much precision as possible.

join_date is a tricky one, I don't know how to approach the implementation of this.

Alternatives

There are many ways to go to implement this, the one in the proposal is how I'd do.

hawkw commented 4 years ago

cc @zekisherif

zekisherif commented 4 years ago

@Karrq Sorry about the delay (busy week).

I agree that custom rotations is sorely needed. If you haven't already started on the implementation, I think I'll be able to starting Wednesday

JRAndreassen commented 4 years ago

Hi...

I would like to see this change as well... I had the same thought about making the Duration the a parameter... Thanks JR