Skip to main content

Peeklog

PyPI Python License

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() replaces logging.getLogger() and comes pre-wired with console + rotating/compressed file handlers.
  • CLI and library are the same engine - anything you can do with peeklog analyze you can also do programmatically with LogAnalyzer.

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 parsing
  • peeklog.analyzer - LogAnalyzer, AnalysisResult: aggregation & stats
  • peeklog.anomalies - AnomalyDetector, Anomaly: z-score spikes, IQR outliers, silence gaps, error bursts
  • peeklog.reports - ReportGenerator: Rich terminal reports
  • peeklog.exporters - JSONExporter, PDFExporter: JSON and charted-PDF export
  • peeklog.decorators - logged, timed, retry, log_errors: function instrumentation
  • peeklog.logger / peeklog.rotation - configurable logging with compressed rotation
  • peeklog.exceptions - ApplicationException
  • peeklog.cli - the peeklog command above

Contributing

Issues and PRs welcome - see GitHub Issues.

License

Apache-2.0 - see LICENSE.

Metadata

Release files for peeklog 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for peeklog 1.0.0
File Size Uploaded Provenance Actions
peeklog-1.0.0.tar.gz 51.2 kB Without provenance Details for peeklog-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for peeklog 1.0.0
File Interpreter ABI Platform Actions
peeklog-1.0.0-py3-none-any.whl Python 3 none any Details for peeklog-1.0.0-py3-none-any.whl

Total release size: 99.5 kB

Release files / peeklog-1.0.0.tar.gz

Download URL peeklog-1.0.0.tar.gz
Size 51.2 kB
Tags Source
SHA-256 checksum
How to use checksums
acd15129a18772a46f314e4553e1091da20f67ee3d119ecc10978a369b149246
BLAKE2b-256 checksum
How to use checksums
d4ff0a5294d000ed38af7cac61a84aeef7cc42dab123d2bee00010e786d9490f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.19

Release files / peeklog-1.0.0-py3-none-any.whl

Download URL peeklog-1.0.0-py3-none-any.whl
Size 48.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
142b0d7ed677839e6363baa1402c23cde7519197fac02822f086b37ae41f2cef
BLAKE2b-256 checksum
How to use checksums
6a60b631ff4ec2c7e2a055d86bd8a6ad9447b6c129b4accf85c41121f425b58c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.19

Security for peeklog 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page