Skip to main content
Log Lens Logo

Log Lens 🔍

Lightweight, fast CLI for analyzing Apache/Nginx server logs with auto-format detection, rich formatting, and JSON export.

PyPI version Tests Coverage Code style: black Python 3.12+


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

  1. Fork & clone
  2. pip install -e '.[dev]'
  3. poetry run pre-commit install
  4. Make changes + write tests
  5. poetry run pytest tests/ -v --cov=log_lens (must pass)
  6. poetry run pre-commit run --all-files (must pass)
  7. Commit & push
  8. Submit PR

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


Questions? Open an issue or start a discussion.

Happy analyzing! 🔍✨

Metadata

Release files for log-lens 0.7.1

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

Source distribution (sdist)

Source distribution for log-lens 0.7.1
File Size Uploaded
log_lens-0.7.1.tar.gz 8.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for log-lens 0.7.1
File Interpreter ABI Platform
log_lens-0.7.1-py3-none-any.whl Python 3 none any Details

Total release size: 18.0 kB

Release files / log_lens-0.7.1.tar.gz

Download URL log_lens-0.7.1.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
fd4772070d606aeb96775c97ea43a2b2b94fb49bc0b214a878708234181a6881
BLAKE2b-256 checksum
How to use checksums
88bc514a1173efaac31f7175d3724ecee778c15c387b87051343bdea9e95ff62
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.2 CPython/3.14.3 Darwin/24.6.0

Release files / log_lens-0.7.1-py3-none-any.whl

Download URL log_lens-0.7.1-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ca3af0cd59917abd09535178d161630d2de652c62cd09de06cacb94cf4be54f8
BLAKE2b-256 checksum
How to use checksums
9fe80d8e762af50b6efbb4c470382ff32ebbffdb1cfcb8e769f3d4bdcefd95a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.2 CPython/3.14.3 Darwin/24.6.0

Release history Release notifications | RSS feed

This release

0.7.1 This release

2 release files

0.4.0

2 release files

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