Firo
firo is a straightforward crate, inspired by std::fs::File,
providing the necessary APIs to implement rotating files.
It currently supports:
- rotation trigger based on time
- rotation trigger based on size
- file compression (at rotation time)
- maximum size limit, oldest files will start being deleted if the sum of all files sizes goes beyond the limit
- transparently reading a rotating file
Usage Example
Basic
use ;
use Write;
use Duration;
let td = tempdir.unwrap;
// we initialize a rotating file options
let mut f = options
// file will rotate every hours
.trigger
// finally create the file
.create_append.unwrap;
// one can use File as std::fs::File
for _ in 0..1000
Advanced
Rotating file based on size, enabling compression and deleting old files when total size reaches a given threshold.
use ;
use ByteSize;
use tempfile;
use ;
let td = tempdir.unwrap;
let p = td.path.join;
// we initialize a rotating file options
let opts = options
// file will rotate when reaching 1 KB
.trigger
// gzip compression is enabled (at rotation time)
.compression
// we start deleting oldest file when total size > 1 GB
.max_size;
let mut f = opts
// finally create the file
.create_append.unwrap;
// one can use File as std::fs::File
for i in 0..100_000
// make sure there are no pending writes
f.sync.unwrap;
// one can also read a rotating file
let f = opts.open.unwrap;
// we check that file is actually made of several
// files on disk (just for the demo)
assert!;
let reader = new;
let mut lines = reader.lines;
for i in 0..100_000