poll-tail
A simple, polling-based file tailer that gracefully handles log rotation.
poll-tail provides a FileListener that monitors a file for changes, similar to tail --follow. It's designed to be robust against file truncation, replacement, and deletion, which are common with log rotation mechanisms.
It operates on a synchronous, polling basis via the tick() method, making it extremely easy to integrate into any application loop without needing an async runtime or complex event-driven dependencies.
Key Features
- Simple Polling API: Just call
tick()periodically in your loop. - Log Rotation Handling: Seamlessly handles file truncation, deletion, and recreation.
- Backfilling: Can be configured to read the last N lines of a file when it first appears.
- Customizable Parser: Provides a default RFC 3339 timestamp parser but allows you to supply your own logic for parsing lines.
- No Async: Purely synchronous, making it perfect for simple clients, tools, or existing application loops.
Installation
Add the following to your Cargo.toml:
[]
= "0.1.0" # use the latest version
Usage
Here's a basic example that follows a log file and prints new lines as they appear.
use ;
use ;
API Overview
FileListener: The main struct that holds the file state and line buffer.FileListenerBuilder: A convenient builder for configuring the listener.tick(): The primary method you call to check for file updates.lines(): Returns a reference to the internalVecDequeof(DateTime<Utc>, String)tuples.Error: Athiserror-based enum for all possible failures.
License
This project is licensed under the MIT license.