| Crates.io | tailf |
| lib.rs | tailf |
| version | 0.1.2 |
| created_at | 2024-11-15 11:38:11.804358+00 |
| updated_at | 2024-11-18 02:38:04.192104+00 |
| description | A async `tail -f` for files |
| homepage | |
| repository | https://github.com/kvinwang/tailf |
| max_upload_size | |
| id | 1449027 |
| size | 15,456 |
A Rust library that provides an async file tailing functionality using the system's tail command, powered by tokio::process::Command.
Add this to your Cargo.toml:
[dependencies]
tailf = "0.1.0"
use tailf::tailf;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Read last 10 lines and follow new updates
let num_lines = 10;
let mut tailer = tailf("/var/log/syslog", Some(num_lines));
while let Some(line) = tailer.next().await? {
let line_str = String::from_utf8_lossy(&line);
print!("{}", line_str);
std::io::stdout().flush()?;
}
Ok(())
}
The underlying tail process is automatically terminated when the tailer instance is dropped.
This project is licensed under the MIT License - see the LICENSE file for details.