Function watch_log

Source
pub async fn watch_log<P: AsRef<Path>>(
    path: P,
    separator: Option<String>,
) -> Result<impl Stream<Item = Result<Vec<String>>>>
Expand description

Creates a stream that watches a file for new content.

§Arguments

  • path - File path to monitor
  • separator - Content separator (defaults to newline)

§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 {
        for line in lines? {
            println!("New line: {}", line);
        }
    }
     
    Ok(())
}