Crate log_reader

Crate log_reader 

Source
Expand description

A log reader library that provides real-time streaming of file contents.

This library monitors files for changes and emits new content as an async stream, with handling of file appends by tracking read positions.

§Example

use log_reader::watch_log;
use tokio_stream::StreamExt;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut stream = watch_log("app.log", None).await?;
     
    while let Some(lines) = stream.next().await {
        match lines {
            Ok(content) => {
                for line in content {
                    println!("New line: {}", line);
                }
            }
            Err(e) => eprintln!("Error: {}", e),
        }
    }
     
    Ok(())
}

Structs§

LogStream
A stream that monitors a file for changes and yields new content.

Enums§

Error
The main error type for log reader operations.

Functions§

watch_log
Creates a stream that watches a file for new content.

Type Aliases§

Result
A convenient Result type for log reader operations.