Crate filetrack

source ·
Expand description

Filetrack

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
let inner_items = vec![Cursor::new(vec![1, 2, 3]), Cursor::new(vec![4, 5])];
// we get result here because Multireader performs seek
// (fallible operation) under the hood to determine sizes
let mut reader = Multireader::new(inner_items)?;
reader.read_to_end(&mut buf)?;
assert_eq!(buf, vec![1, 2, 3, 4, 5])
  • TrackedReader that allows to read logs or any other content from rotated files with offset persisted across restarts
// running this program multiple times will output next line on each execution
let mut reader = TrackedReader::new("examples/file.txt", "examples/registry")?;
match reader.read_line(&mut input)? {
    0 => println!("reached end of file"),
    _ => println!("read line: `{}`", input.trim_end()),
};

See documentation for examples and working principles.

Structs

  • Structure that provides seeking and reading in a sequence of underlying readables
  • Structure used to store state of TrackedReader
  • Structure that implements Read, ReadBuf and Seek while working with persistent offset in up to two underlying logrotated files. External file is used to persist offset across restarts.

Enums

  • Possible errors that could happen while working with persistent state storage
  • Possible errors that could happen while working with TrackedReader