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(lines) = stream.next().await {
17//! match lines {
18//! Ok(content) => {
19//! for line in content {
20//! println!("New line: {}", line);
21//! }
22//! }
23//! Err(e) => eprintln!("Error: {}", e),
24//! }
25//! }
26//!
27//! Ok(())
28//! }
29//! ```
30
31// Internal modules - not part of public API
32mod error;
33mod reader;
34mod stream;
35mod watcher;
36
37#[cfg(test)]
38mod test_helpers;
39
40// Public API exports
41pub use error::{Error, Result};
42pub use stream::LogStream;
43
44use std::path::Path;
45use tokio_stream::Stream;
46
47/// Creates a stream that watches a file for new content.
48///
49/// # Arguments
50///
51/// * `path` - File path to monitor
52/// * `separator` - Content separator (defaults to newline)
53///
54/// # Example
55///
56/// ```rust,no_run
57/// use log_reader::watch_log;
58/// use tokio_stream::StreamExt;
59///
60/// #[tokio::main]
61/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
62/// let mut stream = watch_log("app.log", None).await?;
63///
64/// while let Some(lines) = stream.next().await {
65/// for line in lines? {
66/// println!("New line: {}", line);
67/// }
68/// }
69///
70/// Ok(())
71/// }
72/// ```
73pub async fn watch_log<P: AsRef<Path>>(
74 path: P,
75 separator: Option<String>,
76) -> Result<impl Stream<Item = Result<Vec<String>>>> {
77 LogStream::new(path, separator).await
78}
79
80#[cfg(test)]
81mod tests {
82 #[tokio::test]
83 async fn test_basic_functionality() {
84 // Placeholder test - will be implemented with proper fixtures
85 assert!(true);
86 }
87}