Kelora
Scriptable log processor for the command line. Treats logs as structured events and lets you filter, transform, and analyze them using Rhai scripts.
Quick Start
Scripts use e to access the current log event - e.status, e.level, etc. are the actual fields from your logs.
# Filter JSON logs with enrichment
# Pattern detection with sliding windows
# Real-time monitoring with parallelization
|
# Time-range analysis with metrics
# Docker container monitoring
|
Install
Core Features
Formats: JSON, syslog, logfmt, CEF, CSV, TSV, Docker logs, raw lines with .gz support
Processing: Sliding windows, parallel/batch processing, multiline events
Scripting: Embedded Rhai with 40+ built-in functions for parsing, metrics, time handling
Configuration: Aliases and defaults via config files
Error handling: Resilient mode with robust error recovery, strict mode for fail-fast behavior
Rhai Examples
// Filter and enrich
e.level == "error" && e.response_time.to_int() > 1000
e.severity = if e.status >= 500 { "critical" } else { "warning" }
// Pattern detection
let ips = window_values(window, "ip"); ips.contains("192.168.1.100")
// Extract and transform
let user = e.line.extract_re("user=(\w+)");
e.masked_ip = e.ip.mask_ip(2)
// Track metrics and use safety functions
track_count("requests"); track_max("peak_latency", get_path(e, "duration_ms", 0))
Working with Events
The e variable represents the current event. Access fields directly (e.level) or use bracket notation for invalid identifiers (e["content-type"]). Add fields by assignment (e.severity = "critical").
// Field access and modification
e.level == "error" // Direct access
e["user-agent"] = "kelora/1.0" // Invalid identifiers need brackets
e.processed = now_utc() // Add new fields
// Field and event removal with unit ()
e.password = () // Remove individual fields
e = () // Remove entire event (clears all fields)
// Method vs function style (both work, methods chain better)
e.ip.mask_ip(2) // Method style
mask_ip(e.ip, 2) // Function style (avoids conflicts)
// Safety functions with fallbacks
get_path(e, "user.profile.id", "unknown") // Safe nested access
to_number(e.port, 80) // Safe conversion with default
Common Use Cases
# Error analysis with time grouping
# Convert formats with field selection
# Docker container log analysis
|
# Strict mode for validation (fail-fast on errors)
# Performance testing with output suppression
# Multiline processing (stack traces)
# Field selection and filtering
# Output formatting
# Output control for automation
# Configuration aliases
Key Options
| Flag | Purpose | Example |
|---|---|---|
-f FORMAT |
Input format | jsonl, syslog, csv, docker, auto (detects from first line) |
-F FORMAT |
Output format | jsonl, csv, logfmt, null, hide |
--filter EXPR |
Include matching events | e.level == "error" |
--exec SCRIPT |
Transform events | e.type = "slow" |
-c, --core |
Output only core fields | Essential fields only |
-b, --brief |
Output only field values | No field names, just values |
-l LEVELS |
Include only these log levels | -l error,warn |
-L LEVELS |
Exclude these log levels | -L debug,trace |
-k FIELDS |
Output only specific fields | -k timestamp,level,msg |
-K FIELDS |
Exclude specific fields | -K password,secret |
-S, --stats-only |
Show stats with no output | Stats only, no events |
--window N |
Sliding window size | --window 5 |
--parallel |
Parallel processing | Higher throughput |
--since/--until |
Time filtering | "2024-01-01", "1 hour ago" |
--strict |
Fail-fast error handling | Abort on first error |
--verbose |
Detailed error information | Show error details |
See kelora --help for the complete reference.
Configuration
Create ~/.config/kelora/config.ini for defaults and aliases:
[defaults]
format = auto # Auto-detect input format from first line
stats = true # Always show stats
parallel = true # Use parallel processing
[alias.errors]
format = auto
filter = e.level == "error"
keys = timestamp,level,msg
stats = true
[alias.slow-requests]
format = auto
filter = e.response_time.to_int() > 1000
exec = e.severity = "slow"
Advanced Features
Window Analysis: Detect patterns across event sequences with --window N
Timezone Handling: Parse input in one timezone, display in another
Built-in Functions: 40+ functions for string processing, time parsing, metrics tracking
- String:
extract_re(),extract_ip(),mask_ip() - Time:
parse_timestamp(),parse_duration(),now_utc() - Data:
parse_json(),parse_kv(),get_path(),has_path(),path_equals() - Safety:
to_number(),to_bool()for robust type conversion - Metrics:
track_count(),track_max(),track_unique()
Error Handling Modes:
- Resilient (default): Skip errors, continue processing, show summary at end
- Strict (
--strict): Fail-fast on any error with immediate error display - Context-specific: Parsing errors skip lines, filter errors skip events, exec errors roll back changes
Help & Documentation
Not a Replacement For
- Log browsing: Use
lnav - Full-text search: Use
ripgrep - Dashboards: Use Grafana/Kibana
- JSON pipelines: Use
jq
License: MIT