The lightning-fast, structured log parsing engine built in Rust.
loglens-core is a high-performance library designed to parse, query, and analyze structured logs (JSON, Nginx, Logfmt) at scale. It powers the LogLens CLI.
- Zero-Config Parsing: Automatically detects and parses JSON or Logfmt lines without manual schema definition.
- Structured Query Engine: Filter logs with complex logic using a familiar syntax:
level == "error" && latency > 500. - High Throughput: Optimized for reading gigabytes of logs in seconds, making it suitable for high-volume production environments.
- Time-Aware: Native understanding of timestamps for time-range filtering.
Add this to your Cargo.toml:
[dependencies]
loglens-core = "0.1.0"Here is how you can use loglens-core to parse a log line and run a structured query against it:
use loglens_core::{evaluate, LogEntry, parsers::parse_log_line};
fn main() {
// A sample JSON log line
let log_line = r#"{"level": "error", "latency": 502, "msg": "Database timeout", "timestamp": "2023-10-27T10:00:00Z"}"#;
// 1. Parse the raw string into a structured LogEntry
// This automatically detects if it is JSON or Logfmt
let entry = parse_log_line(log_line);
// 2. Define a query
// Returns true if latency is greater than 500 AND level is "error"
let query = "latency > 500 && level is error";
// 3. Evaluate the query against the parsed entry
if let LogEntry::Structured(value) = entry {
// 'evaluate' returns a Result<bool, QueryError>
match evaluate(&value, log_line, query) {
Ok(true) => println!("✅ Match found!"),
Ok(false) => println!("❌ No match."),
Err(e) => eprintln!("Query error: {}", e),
}
} else {
println!("Could not parse as structured log.");
}
}This library is the engine behind LogLens, a terminal-based log explorer that replaces jq and tail -f with a powerful TUI.
LogLens Pro features:
- 📊 Interactive TUI: Filter and explore logs with keyboard shortcuts.
- 👀 Live Watch: Real-time filtering and highlighting (
loglens watch). - 📈 Instant Stats: Automatic field analysis and error rate calculation.
brew tap Caelrith/loglens
brew install loglensContributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.
