Lightweight CLI for analyzing Apache/Nginx server logs
Project description
Log Lens ๐
Lightweight, fast CLI for analyzing Apache/Nginx server logs with auto-format detection, rich formatting, and JSON export.
โจ Features
- โ Auto log format detection - Apache, generic, and more
- ๐ฏ Status codes analysis - 200, 404, 500 breakdowns
- ๐ Top IPs, paths, & HTTP methods - Rich table visualization
- ๐จ Rich CLI output - Colors, tables, formatted display
- ๐ JSON export - For dashboards, tools, and pipelines
- ๐งช Production ready - 95% test coverage, strict linting, CI/CD
- โก Zero dependencies in runtime
๐ Quick Start
Install
pip install log-lens
Or from source:
git clone https://github.com/KnowOneActual/log-lens.git
cd log-lens
pip install -e .
Basic Usage
# Analyze a log file
log-lens /path/to/access.log
# Export to JSON
log-lens access.log -e report.json
# Limit top IPs to 5
log-lens access.log --top-ips 5
# Help
log-lens --help
๐ Usage Examples
Apache Access Logs
log-lens /var/log/apache2/access.log
Output:
โ
Analyzed /var/log/apache2/access.log: 1,234 lines
๐ Found 1,234 entries
๐ Format: APACHE
โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโ
โ Status Codes โ โ Top IPs โ
โโโโโโโโโโโโโโโโโโค โโโโโโโโโโโโโโโโโโค
โ 200 โ 892 โ โ 192.168.1.100 โ 156
โ 404 โ 45 โ โ 10.0.0.15 โ 89
โ 500 โ 8 โ โ 172.16.0.50 โ 42
โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโ
โ HTTP Methods โ โ Top Paths โ
โโโโโโโโโโโโโโโโโโโโโโค โโโโโโโโโโโโโโโโโโโโโค
โ GET โ 945 โ โ / โ 234
โ POST โ 87 โ โ /api/login โ 89
โ HEAD โ 134 โ โ /assets/style.css โ 67
โโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโ
Export JSON for Dashboards
log-lens access.log -e metrics.json
cat metrics.json
Output:
{
"format": "apache",
"ips": {
"192.168.1.100": 156,
"10.0.0.15": 89
},
"status_codes": {
"200": 892,
"404": 45,
"500": 8
},
"top_paths": {
"/": 234,
"/api/login": 89,
"/assets/style.css": 67
},
"methods": {
"GET": 945,
"POST": 87,
"HEAD": 134
}
}
Limit Results
# Show only top 5 IPs
log-lens access.log --top-ips 5
๐ Development Setup
Prerequisites
- Python 3.12+
- Poetry
- Git
Install Development Environment
git clone https://github.com/KnowOneActual/log-lens.git
cd log-lens
# Install with dev dependencies
pip install -e '.[dev]'
# Install pre-commit hooks (auto-formatting)
poetry run pre-commit install
Running Tests
# Run all tests
poetry run pytest tests/ -v
# Run with coverage
poetry run pytest tests/ -v --cov=log_lens
# Run specific test
poetry run pytest tests/test_cli.py::TestCliIntegration -v
Expected output (95% coverage):
========== 11 passed in 0.24s ==========
---------- coverage: platform darwin, python 3.12.2-final-0 ----------
Name Stmts Miss Cover
------------------------------------------
log_lens/__init__.py 4 0 100%
log_lens/cli.py 73 7 90%
log_lens/parser.py 52 0 100%
------------------------------------------
TOTAL 129 7 95%
Code Quality
# Format code
poetry run black log_lens/ tests/
# Sort imports
poetry run isort log_lens/ tests/
# Lint
poetry run ruff check log_lens/ tests/
# Run ALL checks at once
poetry run pre-commit run --all-files
๐ Pre-Commit Checklist
Always run this before committing:
# Run tests
poetry run pytest tests/ -v --cov=log_lens
# Run all formatters & linters
poetry run pre-commit run --all-files
See PRE_COMMIT_CHECKLIST.md for detailed workflow.
If formatters modify files:
git add .
git commit -m "style: format code"
poetry run pre-commit run --all-files # Re-run to verify
๐ค Contributing
Contributions welcome! Please read CONTRIBUTING.md for:
- Development workflow
- Commit message format
- Testing requirements
- PR guidelines
Quick summary:
- Fork & clone
pip install -e '.[dev]'poetry run pre-commit install- Make changes + write tests
poetry run pytest tests/ -v --cov=log_lens(must pass)poetry run pre-commit run --all-files(must pass)- Commit & push
- Submit PR
๐ Documentation
- README.md - This file, getting started
- CONTRIBUTING.md - Development workflow & guidelines
- PRE_COMMIT_CHECKLIST.md - Testing checklist before commits
- CHANGELOG.md - Version history
- JSON_SCHEMA.md - JSON export format
- docs/ - Additional documentation
๐ Project Structure
log-lens/
โโโ log_lens/ # Main package
โ โโโ __init__.py
โ โโโ cli.py # CLI entry point
โ โโโ parser.py # Log parsing logic
โโโ tests/ # Test suite (11 tests, 95% coverage)
โ โโโ test_cli.py
โ โโโ test_parser.py
โโโ docs/ # Documentation
โโโ pyproject.toml # Project metadata & dependencies
โโโ poetry.lock # Locked dependencies
โโโ README.md # This file
โโโ CONTRIBUTING.md # Contribution guidelines
โโโ PRE_COMMIT_CHECKLIST.md # Pre-commit testing
โโโ .pre-commit-config.yaml # Auto-formatting hooks
๐ง Technical Stack
- Language: Python 3.12+
- Package Manager: Poetry
- Testing: pytest + pytest-cov (95% coverage)
- Code Quality:
- Black (formatting)
- isort (import sorting)
- Ruff (linting)
- pre-commit (hooks)
- CLI: Rich library for beautiful output
- CI/CD: GitHub Actions
๐ Specifications
Supported Log Formats
- Apache access logs
- Generic syslog format
- Custom logs with log levels
Parsed Data
- Status codes - HTTP response codes (200, 404, 500, etc.)
- IP addresses - Source IPs and frequency
- HTTP methods - GET, POST, HEAD, etc.
- Request paths - Top accessed endpoints
- Log levels - DEBUG, INFO, WARNING, ERROR, CRITICAL
๐ Performance
- Speed: ~5000 lines/sec on typical hardware
- Memory: Minimal (~10MB for 100k log lines)
- Output: Rich tables with ANSI colors
๐ Troubleshooting
"Log format not detected"
The file might be in an unsupported format. Check JSON_SCHEMA.md.
"Permission denied"
Ensure you have read permissions:
chmod +r /path/to/log/file
Tests failing?
See PRE_COMMIT_CHECKLIST.md for debugging.
๐ License
MIT License - See LICENSE for details.
๐ Acknowledgments
Made with โค๏ธ using:
- Rich - Beautiful terminal output
- Black - Code formatting
- pre-commit - Git hooks
- pytest - Testing framework
Questions? Open an issue or start a discussion.
Happy analyzing! ๐โจ
Project details
Release history Release notifications | RSS feed
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 log_lens-0.7.1.tar.gz.
File metadata
- Download URL: log_lens-0.7.1.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.14.3 Darwin/24.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd4772070d606aeb96775c97ea43a2b2b94fb49bc0b214a878708234181a6881
|
|
| MD5 |
662a6407dd149c269fcc63ea68b4d0a6
|
|
| BLAKE2b-256 |
88bc514a1173efaac31f7175d3724ecee778c15c387b87051343bdea9e95ff62
|
File details
Details for the file log_lens-0.7.1-py3-none-any.whl.
File metadata
- Download URL: log_lens-0.7.1-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.14.3 Darwin/24.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca3af0cd59917abd09535178d161630d2de652c62cd09de06cacb94cf4be54f8
|
|
| MD5 |
cd975c0b63f402d8caa9d27ecc02f83f
|
|
| BLAKE2b-256 |
9fe80d8e762af50b6efbb4c470382ff32ebbffdb1cfcb8e769f3d4bdcefd95a9
|