Async log watch

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 (can use the tokio by adding tokio runtime feature) and the notify crate for file system event monitoring.

Usage

Add async-log-watch to your Cargo.toml dependencies:

toml [dependencies] async-log-watch = {version = "0.1"}

Example

```rust use asynclogwatch::{LogWatcher, LogError};

[async_std::main]

async fn main() -> Result<(), Box> { let mut log_watcher = LogWatcher::new();

let filepath = "~/.pm2/logs/r1-out.log";
log_watcher
    .register(filepath, |line: String, err: Option<LogError>| async move {
        if err.is_none() {
            println!("New log line: {}", line);
        } else {
            eprintln!("{}", err.unwrap());
        }
    }, None)
    .await;

log_watcher
    .monitoring(std::time::Duration::from_secs(1))
    .await?;
Ok(())

} ```

Cargo Features

This crate allows you to use tokio runtime featured in async-std by specifying features in your Cargo.toml. By default, it uses async-std with the attributes feature.

To use the crate with the default configuration, add the following line to your Cargo.toml:

toml async-log-watch = "0.1"

To use a specific Tokio configuration, specify the feature like this:

toml my-crate = { version = "0.1", features = ["tokio1"] }

Available Features

Please note that you should only enable one of these features at a time.

TODO

support tokio runtime - [x] ~~Add support for other async runtimes (tokio)~~ - [x] Add support tokio runtime features in async-std

Add filtering options to process specific log lines based on patterns - [x] Add filtering option

Future Works

License

This project is licensed under the MIT License - see the LICENSE file for details.