11 unstable releases (4 breaking)

0.6.2 May 30, 2023
0.6.1 May 30, 2023
0.5.1 May 29, 2023
0.4.1 Jun 5, 2020
0.1.1 Jun 3, 2020

#326 in Compression

Download history 13/week @ 2024-02-18 17/week @ 2024-02-25 1/week @ 2024-03-03 7/week @ 2024-03-10 64/week @ 2024-03-31

64 downloads per month

MIT license

21KB
378 lines

file-rotator

docs.rs badge

Installation

You can add it to your Cargo.toml manually, but my favorite method is via cargo-edit

$ cargo add file-rotator

Usage

For usage instructions, and to learn what a "rotating file" is, please check out the documentation on docs.rs

Reasoning

I've created this crate to allow its usage in my other project, redditbg.rs, so that I can have logging without having to worry about using up literally all of the bytes on my disk


lib.rs:

Simple crate that allows easy usage of rotating logfiles by faking being a single std::io::Write implementor

Alright, sure, but what's a rotating logfile?

Well, imagine we are logging a lot, and after a while we use up all our disk space with logs. We don't want this, nobody wants this, so how do we solve it?

We'll introduce the concept of changing what file we log to periodically, or in other words, we'll rotate our log files so that we don't generate too much stored logging.

One of the concepts that is involved in rotation is a limit to how many log files can exist at once.

Examples

To demostrate what was said above, here's to create a file which rotates every day, storing up to a week of logs in /logs

RotatingFile::new(
    "loggylog",
    "/logs",
    RotationPeriod::Interval(Duration::from_secs(60 * 60 * 24)),
    NonZeroUsize::new(7).unwrap(),
    Compression::None,
);

Dependencies

~3.5MB
~61K SLoC