log_reader/
lib.rs

1//! A log reader library that provides real-time streaming of file contents.
2//!
3//! This library monitors files for changes and emits new content as an async stream,
4//! with handling of file appends by tracking read positions.
5//!
6//! # Example
7//!
8//! ```rust,no_run
9//! use log_reader::watch_log;
10//! use tokio_stream::StreamExt;
11//!
12//! #[tokio::main]
13//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
14//!     let mut stream = watch_log("app.log", None).await?;
15//!     
16//!     while let Some(line) = stream.next().await {
17//!         match line {
18//!             Ok(content) => println!("New content: {}", content),
19//!             Err(e) => eprintln!("Error: {}", e),
20//!         }
21//!     }
22//!     
23//!     Ok(())
24//! }
25//! ```
26
27// Internal modules - not part of public API
28mod error;
29mod reader;
30mod stream;
31mod watcher;
32
33#[cfg(test)]
34mod test_helpers;
35
36// Public API exports
37pub use error::{Error, Result};
38pub use stream::LogStream;
39
40use std::path::Path;
41use tokio_stream::Stream;
42
43/// Creates a stream that watches a file for new content.
44///
45/// # Arguments
46///
47/// * `path` - File path to monitor
48/// * `separator` - Content separator (defaults to newline)
49///
50/// # Example
51///
52/// ```rust,no_run
53/// use log_reader::watch_log;
54/// use tokio_stream::StreamExt;
55///
56/// #[tokio::main]
57/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
58///     let mut stream = watch_log("app.log", None).await?;
59///     
60///     while let Some(line) = stream.next().await {
61///         println!("New content: {}", line?);
62///     }
63///     
64///     Ok(())
65/// }
66/// ```
67pub async fn watch_log<P: AsRef<Path>>(
68    path: P,
69    separator: Option<String>,
70) -> Result<impl Stream<Item = Result<String>>> {
71    LogStream::new(path, separator).await
72}
73
74#[cfg(test)]
75mod tests {
76    #[tokio::test]
77    async fn test_basic_functionality() {
78        // Placeholder test - will be implemented with proper fixtures
79        assert!(true);
80    }
81}