filetrack

Crates.iofiletrack
lib.rsfiletrack
version0.2.3
sourcesrc
created_at2023-10-08 12:14:51.792154
updated_at2023-10-15 13:14:21.287323
descriptionpersistent logrotated reading and other useful io things
homepage
repositoryhttps://github.com/HectorHW/filetrack
max_upload_size
id997109
size45,147
Vladimir Redkin (HectorHW)

documentation

https://docs.rs/filetrack

README

Filetrack

Rust Latest version Documentation License

Filetrack is a library for persistent reading of logs similar to the mechanisms used in Filebeat and other software alike. It provides a few useful primitives for working with IO and its main intention is to be used for implementation of custom log processors.

  • Multireader that lets you work with a list of readers as if you had one single buffer.

  • InodeAwareReader that allows working with rotated logs and maintating persistent offset inside them. Scheme of persistence is to be implemented by user.

  • TrackedReader that allows to read logs or any other content from rotated files with offset persisted across restarts inside a file in case you want a ready-to-use structure.

Example

Read a file line-by-line keeping track of current offset so that you could start where you left off next time. Note that the library does not force you to use this scheme, you can implement your own persistence scheme using InodeAwareReader.

use filetrack::{TrackedReader, TrackedReaderError};
use std::io::BufRead;

// running this script will fetch and print new lines on each execution
fn main() -> Result<(), TrackedReaderError> {
    let mut reader = TrackedReader::new("examples/file.txt", "examples/registry")?;
    let mut input = String::new();
    loop {
        match reader.read_line(&mut input)? {
            0 => break Ok(()),
            _ => println!("read line: `{}`", input.trim_end()),
        };
    }
}

See documentation for more examples and working principles.

Commit count: 21

cargo fmt