async_log_watch
is a simple Rust library developed as a part of a personal project. It is designed to monitor log files and trigger an async callback whenever a new line is added to the file. The library allows users to easily integrate log file monitoring into their projects, with support for monitoring multiple log files simultaneously.
The primary motivation behind creating this library was to efficiently detect new log lines generated by tools like pm2
. The library is built using the async-std
runtime and the notify
crate for file system event monitoring.
Add async-log-watch
to your Cargo.toml
dependencies:
toml
[dependencies]
async-log-watch= "0.1"
```rust use asynclogwatch::LogWatcher; use async_std::task;
async fn main() -> Result<(), Box
let filepath = "/path/to/log-out.txt";
log_watcher
.register(filepath, |line: String| {
async move {
println!("New log line: {}", line);
}
})
.await;
log_watcher.monitoring().await?;
Ok(())
} ```
thiserror
library. - file errors occurs in spawn. This project is licensed under the MIT License - see the LICENSE file for details.