A small Rust command-line program that scans a log file in parallel and prints lines containing a target keyword.
The current implementation is tuned for Linux-style system logs. By default it
opens /var/log/messages, splits the file into chunks, scans those chunks across
multiple threads, and reports every line containing ERROR.
- Reads large log files using offset-based file reads.
- Splits work across multiple threads.
- Avoids splitting log lines in the middle of a chunk.
- Prints matching lines and a total match count.
- Uses
anyhowfor top-level error context.
- Rust toolchain with Cargo.
- A Unix-like operating system.
- Read access to the configured log file.
The code currently uses std::os::unix::fs::FileExt, so it is not portable to
Windows without changes.
Clone the repository and build it:
cargo buildRun the program:
cargo runIf /var/log/messages is not readable by your user, run against a file you can
read by changing these constants in src/main.rs:
const LOG_FILE_PATH: &str = "/var/log/messages";
const TARGET_KEYWORD: &str = "ERROR";ERROR Lines
May 14 12:00:00 host service[123]: ERROR failed to process request
------------------------------
Log File Size (bytes): 1048576
Total occurrences of 'ERROR': 1
Run the test suite:
cargo testCheck formatting:
cargo fmt --checkRun Clippy:
cargo clippy