8 releases
new 0.1.7 | Jan 10, 2025 |
---|---|
0.1.6 | Jan 5, 2025 |
0.1.5 | Dec 28, 2024 |
0.1.0 | Nov 25, 2024 |
#1243 in Parser implementations
530 downloads per month
Used in clever
30KB
383 lines
CleverLib
A flexible Rust library for processing and analyzing log events with parallel and serial processing strategies.
Features
- Multiple event processing strategies
- Serial processing
- Parallel processing
- Efficient log event parsing
- Automatic log level detection
- Simple and intuitive API
Basic Usage
use cleverlib::event_collection::EventCollection;
use std::fs::File;
use std::io::{BufRead, BufReader};
fn main() {
// Read log file lines
let file: File = File::open("events.log").expect("Failed to open log file");
let lines: Vec<String> = BufReader::new(file)
.lines()
.collect::<Result<Vec<String>, std::io::Error>>()
.expect("Failed to read lines");
// Create event collection
let event_collection: EventCollection = EventCollection::create(&lines).unwrap();
// Print detected log levels
println!("Log Levels: {:?}", event_collection.log_levels);
// Filter events by log level
let error_events: Vec<&Event> = event_collection.filter_log_level("error");
println!("Error Events: {}", error_events.len());
}
Parallel Processing
use cleverlib::event_collection::EventCollection;
use std::fs::File;
use std::io::{BufRead, BufReader};
fn main() {
let file: File = File::open("large_events.log").expect("Failed to open log file");
let lines: Vec<String> = BufReader::new(file)
.lines()
.collect::<Result<Vec<String>, std::io::Error>>()
.expect("Failed to read lines");
// Use parallel processing for large log files
let event_collection: EventCollection = EventCollection::create_par(&lines).unwrap();
println!("Total Events: {}", event_collection.events.len());
println!("Unique Log Levels: {:?}", event_collection.log_levels);
}
Performance Strategies
- Serial Processing:
create()
- Best for smaller log files - Parallel Processing:
create_par()
- Recommended for large log files
Key Methods
create(&lines)
: Process events seriallycreate_par(&lines)
: Process events in parallelfilter_log_level(level)
: Filter events by log levelfilter_log_level_par(level)
: Parallel log level filtering
Log Level Detection
The library automatically detects unique log levels during event processing. Detected levels are stored in event_collection.log_levels
.
Dependencies
- Requires Rayon for parallel processing
- Uses Regex for log parsing
Contributing
Contributions welcome! Please submit pull requests or open issues on the project repository.
Dependencies
~8–18MB
~228K SLoC