pub struct FileTailer { /* private fields */ }Expand description
Tracks a growing file, yielding newly appended complete lines on each
call to [read_new_lines].
See the module-level documentation for the full semantics.
Implementations§
Source§impl FileTailer
impl FileTailer
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Self>
pub fn open(path: impl AsRef<Path>) -> Result<Self>
Open the file at path and seek to its current end.
Subsequent calls to [read_new_lines] return only data appended
after this point — identical to tail -f startup behaviour.
Returns Err if the file does not exist or cannot be opened.
Sourcepub fn read_new_lines(&mut self) -> Result<Vec<String>>
pub fn read_new_lines(&mut self) -> Result<Vec<String>>
Read any newly appended bytes, split into complete lines, and return them. A partial trailing line is buffered until it is terminated.
Both \n and \r\n line endings are stripped. Invalid UTF-8 bytes
are replaced with U+FFFD via String::from_utf8_lossy.
Rotation and truncation are checked before every read. If the path
briefly disappears during a rotation (the window between the old
file being renamed away and the new one being created), this method
returns Ok(vec![]) and retries on the next call.