Metadata-Version: 2.4
Name: mzgb
Version: 0.3.0
Summary: Fast CLI for filtering very large log files by level, pattern, and time range
License: MIT License
        
        Copyright (c) 2024 Mukhtar Saeed
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/mukesudo/mzgb
Project-URL: Repository, https://github.com/mukesudo/mzgb
Project-URL: Issues, https://github.com/mukesudo/mzgb/issues
Keywords: log,filter,cli,grep,logging,devops,tail
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: System Administrators
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: System :: Logging
Classifier: Topic :: Utilities
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: click>=8.1.0
Requires-Dist: rich>=13.0.0
Requires-Dist: python-dateutil>=2.8.0
Provides-Extra: dev
Requires-Dist: pytest>=7.4; extra == "dev"
Requires-Dist: pytest-cov>=4.1; extra == "dev"
Provides-Extra: fast
Requires-Dist: pyahocorasick>=2.0.0; extra == "fast"
Requires-Dist: pybloom-live>=4.0.0; extra == "fast"
Provides-Extra: drain
Requires-Dist: drain3>=0.9.11; extra == "drain"
Provides-Extra: all
Requires-Dist: pyahocorasick>=2.0.0; extra == "all"
Requires-Dist: pybloom-live>=4.0.0; extra == "all"
Requires-Dist: drain3>=0.9.11; extra == "all"
Dynamic: license-file

# mzgb

[![Tests](https://img.shields.io/badge/tests-156%20passing-39d353?style=flat-square)](https://github.com/mukesudo/mzgb)
[![Coverage](https://img.shields.io/badge/coverage-89%25-39d353?style=flat-square)](https://github.com/mukesudo/mzgb)
[![PyPI](https://img.shields.io/badge/pypi-v0.3.0-4af0d0?style=flat-square)](https://pypi.org/project/mzgb)
[![Python](https://img.shields.io/badge/python-3.9+-4af0d0?style=flat-square)](https://pypi.org/project/mzgb)
[![License](https://img.shields.io/badge/license-MIT-white?style=flat-square)](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

```bash
# pip (base)
pip install mzgb

# With fast engines (Aho-Corasick + Bloom filter)
pip install "mzgb[fast]"

# With Drain3 template clustering
pip install "mzgb[drain]"

# Everything
pip install "mzgb[all]"

# 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:

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

## Usage

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

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

# Multi-pattern search (OR logic) — matches any keyword
mzgb --pattern timeout --pattern refused --pattern error 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. **Repeatable** (OR logic). |
| `--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 with Drain3 template clustering. |
| `--follow` | `-f` | Follow file for new lines (like tail -f). |

## Development

```bash
# Run tests
python -m pytest

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

## License

MIT — see [LICENSE](LICENSE)
