fix: add --version option to Click CLI group
Some checks failed
CI / test (3.10) (push) Has been cancelled
CI / test (3.11) (push) Has been cancelled
CI / test (3.12) (push) Has been cancelled
CI / test (3.9) (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / build (push) Has been cancelled

- Added @click.version_option decorator to main() in commands.py
- Imported __version__ from loglens package
- Resolves CI build failure: 'loglens --version' command not found
This commit is contained in:
2026-02-02 09:25:16 +00:00
parent 572eedf7a0
commit ea55f03230

400
README.md
View File

@@ -1,23 +1,22 @@
# LogLens CLI # LogLens CLI
A powerful CLI tool for parsing, analyzing, and providing intelligent summaries of log files. LogLens detects error patterns, highlights anomalies, and outputs human-readable reports with severity classifications and suggested fixes. LogLens is a powerful CLI tool for parsing, analyzing, and summarizing log files. It automatically detects log formats, identifies error patterns, and provides intelligent insights with severity classifications.
## Features ## Features
- **Multi-format Log Parsing**: Support for JSON, syslog (RFC 3164/5424), and Apache/Nginx logs - **Multi-format Support**: Parse JSON, syslog, Apache/Nginx, and raw logs
- **Error Pattern Detection**: Built-in library of 20+ patterns for common errors (exceptions, stack traces, connection failures) - **Smart Error Detection**: Built-in patterns for common error types
- **Severity Classification**: Automatic classification into Critical, Error, Warning, Info, and Debug levels - **Severity Classification**: Categorize issues as critical, error, warning, info, or debug
- **Real-time Analysis**: Pipe support for live log streaming with `--follow` mode - **Interactive Analysis**: Analyze logs interactively or in batch mode
- **Human-readable Reports**: Beautiful table and text outputs with color coding - **Rich Output**: Beautiful terminal tables with color-coded severity levels
- **Unix Tool Integration**: Works seamlessly with grep, sed, and other command-line tools - **Flexible Output**: Export results as tables, JSON, or plain text
- **Pipe Support**: Process logs from stdin for real-time analysis
## Installation ## Installation
### From Source ### From Source
```bash ```bash
git clone https://7000pct.gitea.bloupla.net/7000pctAUTO/loglens-cli.git
cd loglens-cli
pip install -e . pip install -e .
``` ```
@@ -27,368 +26,157 @@ pip install -e .
pip install loglens-cli pip install loglens-cli
``` ```
### Development Installation
```bash
pip install -e ".[dev]"
```
## Quick Start
### Analyze a log file
```bash
# Auto-detect format and analyze
loglens analyze app.log
# Specify format explicitly
loglens analyze app.log --format json
loglens analyze app.log --format syslog
loglens analyze app.log --format apache
# Show detailed output
loglens analyze app.log --verbose
```
### Watch logs in real-time
```bash
# Follow log file updates
loglens watch /var/log/app.log
# Follow with auto-refresh
loglens watch /var/log/app.log --interval 2
```
### Generate summary reports
```bash
# Generate summary report
loglens report app.log
# Generate report with severity breakdown
loglens report app.log --severity
# JSON output for programmatic use
loglens report app.log --json
```
### Check detected patterns
```bash
# List all available patterns
loglens patterns
# Search for specific patterns
loglens patterns --search "connection"
# Show pattern details
loglens patterns --show-exceptions
```
### Pipe support
```bash
# Process logs from stdin
tail -f app.log | loglens analyze -
# Chain with grep
grep "ERROR" app.log | loglens analyze -
# Complex pipeline
cat logs/*.log | loglens analyze -
```
## Usage ## Usage
### Commands ### Basic Analysis
#### analyze
Parse and analyze log files.
```bash ```bash
loglens analyze [OPTIONS] FILE loglens analyze /path/to/logfile.log
``` ```
Options: ### Auto-detect Format
- `--format, -f TEXT`: Log format (auto, json, syslog, apache)
- `--output, -o TEXT`: Output format (table, json, text)
- `--verbose, -v`: Show detailed analysis
- `--json`: Output as JSON
#### watch
Monitor a log file in real-time.
```bash ```bash
loglens watch [OPTIONS] FILE loglens analyze /var/log/syslog
loglens analyze /var/log/apache2/access.log
loglens analyze application.json
``` ```
Options: ### Specify Format Manually
- `--interval SECONDS`: Refresh interval (default: 1.0)
- `--format TEXT`: Log format (auto, json, syslog, apache)
#### report
Generate a summary report.
```bash ```bash
loglens report [OPTIONS] FILE loglens analyze --format json logs/
loglens analyze --format syslog /var/log/messages
``` ```
Options: ### Pipe Support
- `--severity`: Include severity breakdown
- `--output TEXT`: Output format (table, json, text)
- `--json`: Output as JSON
#### patterns
Show available error patterns.
```bash ```bash
loglens patterns [OPTIONS] cat logfile.txt | loglens analyze
grep ERROR system.log | loglens analyze
``` ```
Options: ### Watch Files in Real-time
- `--search TEXT`: Search patterns by name
- `--show-exceptions`: Show exception patterns
- `--show-http`: Show HTTP error patterns
- `--json`: Output as JSON
#### info
Show tool information and configuration.
```bash ```bash
loglens info loglens watch /var/log/syslog
loglens watch --interval 5 /var/log/*.log
``` ```
### Examples ### Generate Reports
#### Analyze JSON logs
```bash ```bash
$ loglens analyze application.json --format json loglens report /var/log/*.log --output report.txt
╭──────────────────────────────────────────────────────────────────────────────╮ loglens report /var/log/*.log --json
│ Log Analysis Summary │
├──────────────────────────────────────────────────────────────────────────────┤
│ Total Lines: 150
│ Parsed: 148 (98.7%)
│ Errors Found: 12
│ Severity: 2 Critical, 5 Error, 3 Warning, 2 Info │
╰──────────────────────────────────────────────────────────────────────────────╯
Top Errors:
[CRITICAL] Database connection failure: 3 occurrences
[ERROR] NullPointerException: 2 occurrences
[WARNING] Deprecated API usage: 2 occurrences
``` ```
#### Generate report with severity ### List Available Patterns
```bash ```bash
$ loglens report server.log --severity --output table loglens patterns
Severity Breakdown: loglens patterns --group exceptions
CRITICAL: ████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 2 loglens patterns --severity error
ERROR: ██████████████████████████████ 15
WARNING: ██████████████████████████░░░░ 10
INFO: ██████████████████████████████ 18
DEBUG: ██████████████░░░░░░░░░░░░░░░░░ 6
``` ```
#### Real-time monitoring ### Get Version
```bash ```bash
$ loglens watch /var/log/app.log --interval 2 loglens --version
Watching: /var/log/app.log
Press Ctrl+C to stop...
Last 5 lines:
[2024-01-15 10:30:45] ERROR: Database connection failed
[2024-01-15 10:30:46] WARNING: High memory usage detected
[2024-01-15 10:30:47] INFO: Connection pool status: healthy
[2024-01-15 10:30:48] ERROR: Request timeout: /api/users
[2024-01-15 10:30:49] CRITICAL: Service unresponsive
``` ```
## Configuration ### Get Help
### Environment Variables ```bash
loglens --help
| Variable | Default | Description |
|----------|---------|-------------|
| `LOGLEVEL` | INFO | Default log level for output |
| `LOGLENSMASK` | false | Enable PII masking in logs |
| `LOGLENSCOLOR` | auto | Color output: auto, always, never |
### Configuration File
Create `~/.loglens/config.yaml`:
```yaml
default_format: auto
output_format: table
color: auto
severity_rules:
critical:
- "Out of memory"
- "Service unresponsive"
error:
- "ERROR"
- "Exception"
warning:
- "WARNING"
- "Deprecated"
``` ```
### Custom Patterns ## Options
Add custom patterns in `~/.loglens/patterns.yaml`: ### Global Options
```yaml | Option | Description |
patterns: |--------|-------------|
- name: "Custom Error" | `-v, --verbosity` | Increase output verbosity (can be used multiple times) |
regex: "CUSTOM_ERROR:.*" | `--config FILE` | Path to a configuration file |
severity: error | `--version` | Show program's version number and exit |
suggestion: "Check custom error documentation"
``` ### Analyze Command
| Option | Description |
|--------|-------------|
| `FILES` | Log files to analyze |
| `--format FORMAT` | Log format: json, syslog, apache, auto (default: auto) |
| `--output FORMAT` | Output format: table, json, text (default: table) |
| `--follow/--no-follow` | Follow file changes |
| `--max-entries N` | Maximum entries to display (default: 100) |
| `--json/--no-json` | Output as JSON |
### Watch Command
| Option | Description |
|--------|-------------|
| `FILES` | Files to watch |
| `--format FORMAT` | Log format |
| `--interval SECONDS` | Refresh interval (default: 1.0) |
| `--max-entries N` | Maximum entries per update |
### Report Command
| Option | Description |
|--------|-------------|
| `FILES` | Log files to include in report |
| `--format FORMAT` | Log format |
| `--output FILE` | Output file path |
| `--json/--no-json` | Output as JSON |
## Supported Log Formats ## Supported Log Formats
### JSON Logs ### JSON
```json ```json
{ {"timestamp": "2023-12-01T10:00:00Z", "level": "error", "message": "Failed to connect to database"}
"timestamp": "2024-01-15T10:30:00Z",
"level": "ERROR",
"message": "Connection refused to database",
"logger": "main",
"service": "api"
}
``` ```
### Syslog (RFC 3164/5424) ### Syslog
``` ```
Jan 15 10:30:00 server-01 app[1234]: ERROR: Connection refused Dec 1 10:00:00 hostname appname[1234]: Error message here
Jan 15 10:30:01 server-01 systemd[1]: Started Application Service
``` ```
### Apache/Nginx ### Apache/Nginx
``` ```
192.168.1.1 - - [15/Jan/2024:10:30:00 +0000] "GET /api/users HTTP/1.1" 200 1234 192.168.1.1 - - [01/Dec/2023:10:00:00 +0000] "GET /api HTTP/1.1" 200 1234
192.168.1.2 - - [15/Jan/2024:10:30:01 +0000] "POST /api/login HTTP/1.1" 401 567 ```
## Configuration
Create a `loglens.yaml` file:
```yaml
verbosity: info
format: auto
output: table
``` ```
## Development ## Development
### Setup 1. Clone the repository:
```bash ```bash
git clone https://7000pct.gitea.bloupla.net/7000pctAUTO/loglens-cli.git git clone https://github.com/yourusername/loglens-cli.git
cd loglens-cli cd loglens-cli
```
2. Install development dependencies:
```bash
pip install -e ".[dev]" pip install -e ".[dev]"
``` ```
### Running Tests 3. Run tests:
```bash ```bash
# Run all tests
pytest tests/ -v pytest tests/ -v
# Run with coverage
pytest tests/ --cov=loglens --cov-report=html
# Run specific test suite
pytest tests/unit/ -v
pytest tests/integration/ -v
``` ```
### Linting
```bash
# Ruff linting
ruff check loglens/
# Type checking
mypy loglens/ --ignore-missing-imports
```
### Code Formatting
```bash
# Black formatting
black loglens/ tests/
# Import sorting
isort loglens/ tests/
```
## Project Structure
```
loglens-cli/
├── loglens/
│ ├── __init__.py
│ ├── __main__.py
│ ├── cli/
│ │ ├── __init__.py
│ │ ├── main.py
│ │ └── commands.py
│ ├── parsers/
│ │ ├── __init__.py
│ │ ├── base.py
│ │ ├── json_parser.py
│ │ ├── syslog_parser.py
│ │ ├── apache_parser.py
│ │ └── factory.py
│ ├── analyzers/
│ │ ├── __init__.py
│ │ ├── patterns.py
│ │ ├── severity.py
│ │ └── analyzer.py
│ ├── formatters/
│ │ ├── __init__.py
│ │ ├── base.py
│ │ ├── table_formatter.py
│ │ ├── json_formatter.py
│ │ └── text_formatter.py
│ └── config.yaml
├── tests/
│ ├── __init__.py
│ ├── conftest.py
│ ├── unit/
│ │ ├── __init__.py
│ │ ├── test_parsers.py
│ │ ├── test_analyzer.py
│ │ └── test_cli.py
│ ├── integration/
│ │ ├── __init__.py
│ │ └── test_end_to_end.py
│ └── fixtures/
├── pyproject.toml
├── README.md
├── LICENSE
└── .env.example
```
## Error Patterns
LogLens includes patterns for:
- **Exceptions**: Python, Java, Node.js stack traces
- **HTTP Errors**: 5xx server errors, connection failures
- **Database Errors**: Connection refused, query timeouts
- **System Errors**: Out of memory, disk space, permissions
- **Security Issues**: Authentication failures, access denied
- **Performance**: High latency, slow queries, timeouts
## Contributing
Contributions are welcome! Please read the contributing guidelines before submitting PRs.
## License ## License
MIT License - see LICENSE file for details. MIT License