Some checks failed
- Added @click.version_option decorator to main() in commands.py - Imported __version__ from loglens package - Resolves CI build failure: 'loglens --version' command not found
183 lines
3.6 KiB
Markdown
183 lines
3.6 KiB
Markdown
# LogLens CLI
|
|
|
|
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
|
|
|
|
- **Multi-format Support**: Parse JSON, syslog, Apache/Nginx, and raw logs
|
|
- **Smart Error Detection**: Built-in patterns for common error types
|
|
- **Severity Classification**: Categorize issues as critical, error, warning, info, or debug
|
|
- **Interactive Analysis**: Analyze logs interactively or in batch mode
|
|
- **Rich Output**: Beautiful terminal tables with color-coded severity levels
|
|
- **Flexible Output**: Export results as tables, JSON, or plain text
|
|
- **Pipe Support**: Process logs from stdin for real-time analysis
|
|
|
|
## Installation
|
|
|
|
### From Source
|
|
|
|
```bash
|
|
pip install -e .
|
|
```
|
|
|
|
### Using pip
|
|
|
|
```bash
|
|
pip install loglens-cli
|
|
```
|
|
|
|
## Usage
|
|
|
|
### Basic Analysis
|
|
|
|
```bash
|
|
loglens analyze /path/to/logfile.log
|
|
```
|
|
|
|
### Auto-detect Format
|
|
|
|
```bash
|
|
loglens analyze /var/log/syslog
|
|
loglens analyze /var/log/apache2/access.log
|
|
loglens analyze application.json
|
|
```
|
|
|
|
### Specify Format Manually
|
|
|
|
```bash
|
|
loglens analyze --format json logs/
|
|
loglens analyze --format syslog /var/log/messages
|
|
```
|
|
|
|
### Pipe Support
|
|
|
|
```bash
|
|
cat logfile.txt | loglens analyze
|
|
grep ERROR system.log | loglens analyze
|
|
```
|
|
|
|
### Watch Files in Real-time
|
|
|
|
```bash
|
|
loglens watch /var/log/syslog
|
|
loglens watch --interval 5 /var/log/*.log
|
|
```
|
|
|
|
### Generate Reports
|
|
|
|
```bash
|
|
loglens report /var/log/*.log --output report.txt
|
|
loglens report /var/log/*.log --json
|
|
```
|
|
|
|
### List Available Patterns
|
|
|
|
```bash
|
|
loglens patterns
|
|
loglens patterns --group exceptions
|
|
loglens patterns --severity error
|
|
```
|
|
|
|
### Get Version
|
|
|
|
```bash
|
|
loglens --version
|
|
```
|
|
|
|
### Get Help
|
|
|
|
```bash
|
|
loglens --help
|
|
```
|
|
|
|
## Options
|
|
|
|
### Global Options
|
|
|
|
| Option | Description |
|
|
|--------|-------------|
|
|
| `-v, --verbosity` | Increase output verbosity (can be used multiple times) |
|
|
| `--config FILE` | Path to a configuration file |
|
|
| `--version` | Show program's version number and exit |
|
|
|
|
### 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
|
|
|
|
### JSON
|
|
|
|
```json
|
|
{"timestamp": "2023-12-01T10:00:00Z", "level": "error", "message": "Failed to connect to database"}
|
|
```
|
|
|
|
### Syslog
|
|
|
|
```
|
|
Dec 1 10:00:00 hostname appname[1234]: Error message here
|
|
```
|
|
|
|
### Apache/Nginx
|
|
|
|
```
|
|
192.168.1.1 - - [01/Dec/2023:10:00:00 +0000] "GET /api HTTP/1.1" 200 1234
|
|
```
|
|
|
|
## Configuration
|
|
|
|
Create a `loglens.yaml` file:
|
|
|
|
```yaml
|
|
verbosity: info
|
|
format: auto
|
|
output: table
|
|
```
|
|
|
|
## Development
|
|
|
|
1. Clone the repository:
|
|
```bash
|
|
git clone https://github.com/yourusername/loglens-cli.git
|
|
cd loglens-cli
|
|
```
|
|
|
|
2. Install development dependencies:
|
|
```bash
|
|
pip install -e ".[dev]"
|
|
```
|
|
|
|
3. Run tests:
|
|
```bash
|
|
pytest tests/ -v
|
|
```
|
|
|
|
## License
|
|
|
|
MIT License
|