Skip to main content

Fast CLI for filtering very large log files by level, pattern, and time range

Project description

mzgb

Tests Coverage PyPI Python License

mzgb (mezgeb — "record" in Amharic) is a fast CLI tool for filtering and navigating very large log files. Streams line by line — no memory issues, no matter the file size.

Filter by log level, regex pattern, or time range. Invert matches, pipe structured JSON/CSV output, scan multiple files at once, and decompress .gz/.bz2 on the fly. Works with plaintext, JSON, and logfmt. Pipes cleanly with kubectl, journalctl, cat, jq, and friends.

Install

# pip
pip install mzgb

# pipx (isolated, recommended)
pipx install mzgb

# Homebrew (macOS)
brew tap mukesudo/mzgb && brew install mzgb

# Scoop (Windows)
scoop bucket add mzgb https://github.com/mukesudo/scoop-mzgb
scoop install mzgb

# Snap (Linux)
snap install mzgb --classic

# Nix
nix run github:mukesudo/mzgb

Or from source:

git clone https://github.com/mukesudo/mzgb.git
cd mzgb
python3 -m mzgb --help

Usage

# Filter by log level
mzgb --level ERROR app.log

# Pattern search with context lines
mzgb --pattern "timeout" -C 2 app.log

# Filter by time range
mzgb --from "2024-01-15 14:00" --to "2024-01-15 15:00" app.log

# Invert — everything EXCEPT DEBUG
mzgb --invert --level DEBUG app.log

# Show line numbers
mzgb -n --level ERROR app.log

# Multiple files / globs
mzgb --level ERROR service-a.log service-b.log
mzgb --level ERROR /var/log/*.log

# Structured output — pipe into jq or pandas
mzgb --output json --level ERROR app.log | jq '.msg'
mzgb --output csv app.log > report.csv

# Compressed logs — .gz and .bz2
mzgb --level ERROR archive.log.gz
mzgb --level ERROR archive.log.bz2

# Pipe from anywhere
kubectl logs pod/api | mzgb --level ERROR
journalctl | mzgb --summary

# Follow live logs
mzgb --follow --level ERROR app.log

Options

Flag Short Description
--level -l Filter by log level (ERROR, WARN, INFO). Repeatable.
--pattern -p Filter by keyword or regex.
--from / --to Time range filter.
--context -C Show N lines before and after each match.
--invert -v Print lines that do not match.
--line-numbers -n Prefix output with source line number.
--no-color Disable ANSI color output.
--output -o Output format: text (default), json, csv.
--summary -s Print a summary table instead of raw lines.
--follow -f Follow file for new lines (like tail -f).

Development

# Run tests
python -m pytest

# Run with coverage
python -m pytest --cov=mzgb

License

MIT — see LICENSE

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mzgb-0.2.0.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mzgb-0.2.0-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file mzgb-0.2.0.tar.gz.

File metadata

  • Download URL: mzgb-0.2.0.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for mzgb-0.2.0.tar.gz
Algorithm Hash digest
SHA256 173288de0cf7d1ab6c2bb8e8901d54247455eae0d9820f67135e92361a736448
MD5 ebcfc17597d0a4bd29a98d6fcbc220ff
BLAKE2b-256 5e68b13cf6d624092328fa5a07f5afcc619afdd4b19c6b6e4bb058a5e0aba6d3

See more details on using hashes here.

File details

Details for the file mzgb-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: mzgb-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 16.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for mzgb-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2fe0460bbb0ae27789123eec5fc7af22ec9601a5cdda77a4edd1bf42abcbcb8b
MD5 9d13d349a6e08f6d76feba28684f09c0
BLAKE2b-256 298584507303217a93545dcc96715782193a58ea412bfa749deb69ee2015faa4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page