Math Log Parser
Parse log files and evaluate embedded mathematical expressions for performance analysis.
Use Case
Application logs often contain computed metrics inline:
[INFO] Request latency avg=(12+8+15+22+9)/5 = 13.2ms | p99=(45+52)/2=48.5ms
[INFO] Cache hit ratio = (1024 - 128)/1024 * 100 = 87.5%
[INFO] Queue depth = max(3, 7, 2) = 7
This tool extracts and evaluates these expressions to verify correctness.
Features
- Extract arithmetic expressions from log lines
- Safely evaluate mathematical expressions (no code execution)
- Compute aggregate statistics (mean, median, p95, p99)
- Generate summary dashboards from log files
- Support for custom formula evaluation
Usage
# Parse a log file and verify all expressions
python scripts/parse.py --log app.log --verify
# Generate statistics summary
python scripts/parse.py --log app.log --summary --output stats.json
# Extract and evaluate all expressions
python scripts/parse.py --log app.log --extract-expressions
Safety
Expression evaluation uses a restricted math parser that only allows:
- Basic arithmetic (+, -, *, /, %)
- Numeric literals
- Parentheses for grouping
- Built-in math functions: abs, min, max, round, sqrt, pow, log, log10, ceil, floor
No code execution, no variable binding, no attribute access.

