Peeklog
Peeklog is a streaming log-file analyzer and a drop-in logging helper for Python. Point it at a log file (plain or .gz) and get level breakdowns, top errors, minute/hour/day timelines, statistical anomaly detection, and a Rich terminal report - as a CLI, a library, or both. It also ships a get_logger() helper so you can set up console + rotating, gzip-compressed file logging in one line instead of hand-rolling logging.handlers boilerplate every time.
$ peeklog summary app.log
╭─────────────────────────────────────────────────╮
│ 🔍Peeklog Analysis Report │
│ File: app.log Analyzed: 2026-08-29T12:00:00 │
╰─────────────────────────────────────────────────╯
╭────────────── File Overview ───────────────╮
│ 📁 File Size 355.7 KB │
│ 📄 Total Lines 5,000 │
│ ⚠️ Error Rate 13.24% │
╰────────────────────────────────────────────╯
Why Peeklog
- Streams, doesn't load. Files are parsed line-by-line with bounded memory, so multi-gigabyte logs are fine.
- Auto-detects format. ISO/Python-
logging-style app logs, Apache combined, Nginx error logs, and syslog are recognized out of the box; a custom regex covers everything else. - Real anomaly detection, not just
grep ERROR: z-score spikes, IQR outliers, error bursts, and silence gaps. - One-line logging setup.
get_logger()replaceslogging.getLogger()and comes pre-wired with console + rotating/compressed file handlers. - CLI and library are the same engine - anything you can do with
peeklog analyzeyou can also do programmatically withLogAnalyzer.
Install
pip install peeklog
Requires Python 3.11+. Installing the package pulls in rich, typer, reportlab, and matplotlib (the last two power PDF export with charts).
Command line
Peeklog installs a peeklog command with one subcommand per task:
peeklog summary app.log # quick summary: levels, top errors, anomaly count
peeklog analyze app.log # full report: timeline, sources, samples, anomalies
peeklog anomalies app.log --min-severity high
peeklog timeline app.log --from 2026-01-01 --to 2026-01-07
peeklog search app.log "timeout|refused" --level ERROR --limit 100
peeklog export app.log report.pdf # or report.json — format from the extension
peeklog compress logs/ --older-than 7 --format gz
peeklog decompress logs/app.log.2026-01-01.gz
peeklog version
Every subcommand supports --pattern (regex filter), --from/--to (date range), and --level (comma-separated levels) where relevant. Run peeklog <command> --help for the full option list — for example:
$ peeklog analyze --help
Usage: peeklog analyze [OPTIONS] LOG_FILE
Full analysis of a log file. Parses, classifies, detects anomalies, and
prints a complete report.
Examples:
peeklog analyze server.log
peeklog analyze app.log --pattern "database" --from 2026-01-01 --level ERROR,CRITICAL
peeklog analyze nginx.log --pdf report.pdf --json report.json
Options:
-p, --pattern TEXT Regex filter pattern (case-insensitive).
-f, --from DATE Start date filter (YYYY-MM-DD).
-t, --to DATE End date filter (YYYY-MM-DD).
-l, --level TEXT Comma-separated levels: ERROR,WARNING,…
--no-progress Disable progress bar.
--top INTEGER Number of top messages to show. [default: 20]
--json PATH Export JSON report to this path.
--pdf PATH Export PDF report to this path.
Library
from peeklog import LogAnalyzer, AnomalyDetector, ReportGenerator
result = LogAnalyzer().analyze("app.log")
result.anomalies = [a.to_dict() for a in AnomalyDetector().detect(result)]
ReportGenerator().print_summary(result) # or print_full_report(result)
print(result.error_rate) # % of parsed lines that were ERROR/CRITICAL
print(result.summary_stats) # compact dict of the headline numbers
result.to_dict() # full, JSON-serializable result
Supported log formats are auto-detected line by line: ISO-8601 / Python-logging-style application logs, Apache combined log format, Nginx error logs, and syslog. For anything else, pass a compiled regex with level, time, and message named groups:
import re
from peeklog import LogParser
pattern = re.compile(
r"^(?P<time>\S+ \S+)\|(?P<level>\w+)\|\w+\|(?P<message>.*)$"
)
for entry in LogParser(custom_pattern=pattern).parse_file("custom.log"):
print(entry.level, entry.timestamp, entry.message)
Exporting reports
from peeklog import JSONExporter, PDFExporter
JSONExporter(indent=2).export(result, "report.json")
PDFExporter(include_charts=True).export(result, "report.pdf") # bar + trend charts via matplotlib
Instrumentation decorators
Small, dependency-free decorators for logging/timing/retrying ordinary functions — handy in data pipelines, scripts, and background jobs:
from peeklog import get_logger, logged, timed, retry, log_errors
log = get_logger("pipeline")
@logged(logger=log, show_result=True) # logs the call and its return value
@timed(logger=log) # logs how long it took
def load_batch(batch_id: int) -> list[int]: ...
@retry(times=3, delay=1.0, backoff=2.0, exceptions=(ConnectionError,))
def flaky_upload(rows: list[int]) -> str: ...
@log_errors(reraise=False, default=None) # log the traceback, don't crash the pipeline
def risky_step(rows: list[int]) -> str: ...
Logging helper
from peeklog import get_logger
log = get_logger("etl") # console + ./logs/etl.log, daily rotation + gzip
log.info("starting run")
get_logger() is a drop-in replacement for logging.getLogger() - it returns a normal logging.Logger, so every existing call site keeps working — but it comes pre-configured with a console handler and a rotating, gzip-compressing file handler. Rotation (daily / size / none), file location, level, and format are all overridable per call or via PEEKLOG_* environment variables - see peeklog.constants.config for the defaults.
from peeklog import compress_file, compress_old_logs, decompress_file
compress_old_logs("logs/", older_than_days=7, fmt="gz", skip_active="app.log")
compress_file("logs/app.log.2026-01-01", fmt="gz")
decompress_file("logs/app.log.2026-01-01.gz")
Examples
The examples/ directory has nine runnable, tested scripts covering the quickstart, custom log formats, anomaly detection, exports, decorators, log rotation, a CI-triage gate, and - if you're generating this kind of code with an AI agent - the recommended logging pattern for tool-calling / agent loops:
cd examples
python generate_sample_logs.py
python 01_quickstart.py
See examples/README.md for the full list.
For AI coding agents
If you're an AI agent (or you're prompting one) working in a repo that uses Peeklog, see AGENTS.md for when to reach for get_logger(), retry, log_errors, and timed() instead of hand-rolled logging boilerplate, plus a canonical snippet to generate.
What's implemented
peeklog.parser-LogParser,LogEntry,LogLevel: streaming, multi-format parsingpeeklog.analyzer-LogAnalyzer,AnalysisResult: aggregation & statspeeklog.anomalies-AnomalyDetector,Anomaly: z-score spikes, IQR outliers, silence gaps, error burstspeeklog.reports-ReportGenerator: Rich terminal reportspeeklog.exporters-JSONExporter,PDFExporter: JSON and charted-PDF exportpeeklog.decorators-logged,timed,retry,log_errors: function instrumentationpeeklog.logger/peeklog.rotation- configurable logging with compressed rotationpeeklog.exceptions-ApplicationExceptionpeeklog.cli- thepeeklogcommand above
Contributing
Issues and PRs welcome - see GitHub Issues.
License
Apache-2.0 - see LICENSE.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file peeklog-1.0.0.tar.gz.
File metadata
- Download URL: peeklog-1.0.0.tar.gz
- Upload date:
- Size: 51.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
acd15129a18772a46f314e4553e1091da20f67ee3d119ecc10978a369b149246
|
|
| MD5 |
aa34c153cf54bd33b13e43c8c1c3c5e9
|
|
| BLAKE2b-256 |
d4ff0a5294d000ed38af7cac61a84aeef7cc42dab123d2bee00010e786d9490f
|
File details
Details for the file peeklog-1.0.0-py3-none-any.whl.
File metadata
- Download URL: peeklog-1.0.0-py3-none-any.whl
- Upload date:
- Size: 48.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
142b0d7ed677839e6363baa1402c23cde7519197fac02822f086b37ae41f2cef
|
|
| MD5 |
55aa4d31d404fc6b38b2f2de15ee70d5
|
|
| BLAKE2b-256 |
6a60b631ff4ec2c7e2a055d86bd8a6ad9447b6c129b4accf85c41121f425b58c
|