gitstq/LogInsight-CLI
GitHub: gitstq/LogInsight-CLI
Stars: 0 | Forks: 0
# 🔍 LogInsight-CLI
**轻量级终端日志智能分析引擎**
*Lightweight Terminal Log Intelligent Analysis Engine* [](https://www.python.org/) [](LICENSE) []() []() [简体中文](#简体中文) | [繁體中文](#繁體中文) | [English](#english)
## 简体中文
### 🎉 项目介绍
**LogInsight-CLI** 是一款零依赖、轻量级的终端日志智能分析工具,专为开发者和运维工程师设计。它能够快速解析各类日志格式,自动识别日志级别,检测异常模式,并生成直观的分析报告。
**核心痛点解决:**
- ❌ 传统日志分析工具(如ELK)部署复杂、资源占用高
- ❌ 命令行工具(如grep/awk)功能单一、学习成本高
- ✅ LogInsight-CLI 零依赖、开箱即用、功能全面
**自研差异化亮点:**
- 🚀 **零依赖**:纯Python标准库实现,无需安装任何第三方包
- 🎯 **智能解析**:自动识别多种时间戳格式和日志级别
- 🚨 **异常检测**:内置智能算法检测错误率异常、日志突发等
- 📊 **多格式输出**:支持文本报告、JSON、CSV格式
- 🖥️ **TUI仪表盘**:终端可视化展示分析结果
- 📦 **gzip支持**:直接分析压缩日志文件
### ✨ 核心特性
| 特性 | 描述 | 状态 |
|------|------|------|
| 🔍 **多格式解析** | 支持ISO 8601、标准格式、系统日志等时间戳 | ✅ |
| 📊 **5级分类** | DEBUG、INFO、WARNING、ERROR、CRITICAL | ✅ |
| 🚨 **异常检测** | 错误率监控、日志突发检测、模式识别 | ✅ |
| 📈 **统计分析** | 日志级别分布、时间范围、Top消息 | ✅ |
| 🖥️ **TUI仪表盘** | 终端可视化界面 | ✅ |
| 📄 **多格式导出** | 文本、JSON、CSV报告 | ✅ |
| 🔄 **实时跟踪** | 类似`tail -f`的实时日志监控 | ✅ |
| 📦 **gzip支持** | 直接读取压缩日志文件 | ✅ |
### 🚀 快速开始
#### 环境要求
- Python 3.8+
- 操作系统:Linux / macOS / Windows
#### 安装方式
**方式1:直接下载使用(推荐)**
# 克隆仓库
git clone https://github.com/gitstq/LogInsight-CLI.git
cd LogInsight-CLI
# 直接使用
python3 loginsight.py --help
**方式2:pip安装**
pip install loginsight-cli
**方式3:Makefile安装**
make install
#### 快速使用
# 分析单个日志文件
python3 loginsight.py /var/log/syslog
# 分析多个日志文件
python3 loginsight.py *.log
# 实时跟踪日志
python3 loginsight.py app.log --follow
# 只显示错误级别及以上
python3 loginsight.py app.log --level ERROR
# 导出JSON报告
python3 loginsight.py app.log --json -o report.json
# 显示TUI仪表盘
python3 loginsight.py app.log --dashboard
### 📖 详细使用指南
#### 命令行参数
positional arguments:
files 日志文件路径(支持通配符和gzip文件)
options:
-h, --help 显示帮助信息
-f, --follow 实时跟踪文件变化(类似tail -f)
-l, --level 只显示指定级别及以上的日志
-n, --lines 只显示最后N行
--start-time 开始时间(格式: YYYY-MM-DD HH:MM:SS)
--end-time 结束时间(格式: YYYY-MM-DD HH:MM:SS)
--pattern 过滤包含指定模式的日志
--exclude 排除包含指定模式的日志
-o, --output 输出报告到文件
--json 输出JSON格式
--csv 输出CSV格式
--dashboard 显示TUI仪表盘
--anomaly-detection 启用异常检测(默认开启)
#### 典型使用场景
**场景1:排查生产环境问题**
# 分析最近1小时的错误日志
python3 loginsight.py /var/log/app.log \
--start-time "2025-01-15 10:00:00" \
--end-time "2025-01-15 11:00:00" \
--level ERROR
**场景2:监控应用启动过程**
# 实时跟踪并高亮错误
python3 loginsight.py app.log --follow --level WARNING
**场景3:生成每日报告**
# 生成JSON格式的分析报告
python3 loginsight.py /var/log/*.log --json -o daily_report.json
### 💡 设计思路与迭代规划
#### 技术选型原因
- **纯Python实现**:保证跨平台兼容性,无需额外依赖
- **零依赖设计**:降低部署门槛,适合容器化和边缘设备
- **模块化架构**:易于扩展新的解析器和检测规则
#### 后续功能迭代计划
- [ ] 支持更多日志格式(Apache、Nginx、JSON Lines)
- [ ] 机器学习异常检测
- [ ] Web界面可视化
- [ ] 日志聚类和模式挖掘
- [ ] 与Prometheus/Grafana集成
#### 社区贡献方向
- 提交新的日志格式解析器
- 完善异常检测规则
- 翻译文档到更多语言
- 分享使用案例
### 📦 打包与部署指南
#### 构建独立可执行文件
# 安装pyinstaller
pip install pyinstaller
# 构建单文件可执行程序
pyinstaller --onefile --name loginsight loginsight.py
# 可执行文件位于 dist/loginsight
#### Docker部署
FROM python:3.11-slim
WORKDIR /app
COPY loginsight.py .
ENTRYPOINT ["python3", "loginsight.py"]
docker build -t loginsight-cli .
docker run -v /var/log:/logs loginsight-cli /logs/syslog
### 🤝 贡献指南
欢迎提交PR和Issue!
**提交规范:**
- `feat:` 新功能
- `fix:` 修复问题
- `docs:` 文档更新
- `refactor:` 代码重构
### 📄 开源协议
本项目采用 [MIT License](LICENSE) 开源协议。
## 繁體中文
### 🎉 專案介紹
**LogInsight-CLI** 是一款零依賴、輕量級的終端日誌智慧分析工具,專為開發者和維運工程師設計。它能夠快速解析各類日誌格式,自動識別日誌級別,檢測異常模式,並生成直觀的分析報告。
**核心痛點解決:**
- ❌ 傳統日誌分析工具(如ELK)部署複雜、資源佔用高
- ❌ 命令列工具(如grep/awk)功能單一、學習成本高
- ✅ LogInsight-CLI 零依賴、開箱即用、功能全面
**自研差異化亮點:**
- 🚀 **零依賴**:純Python標準庫實現,無需安裝任何第三方套件
- 🎯 **智慧解析**:自動識別多種時間戳格式和日誌級別
- 🚨 **異常檢測**:內建智慧演算法檢測錯誤率異常、日誌突發等
- 📊 **多格式輸出**:支援文字報告、JSON、CSV格式
- 🖥️ **TUI儀表盤**:終端視覺化展示分析結果
- 📦 **gzip支援**:直接分析壓縮日誌檔案
### ✨ 核心特性
| 特性 | 描述 | 狀態 |
|------|------|------|
| 🔍 **多格式解析** | 支援ISO 8601、標準格式、系統日誌等時間戳 | ✅ |
| 📊 **5級分類** | DEBUG、INFO、WARNING、ERROR、CRITICAL | ✅ |
| 🚨 **異常檢測** | 錯誤率監控、日誌突發檢測、模式識別 | ✅ |
| 📈 **統計分析** | 日誌級別分佈、時間範圍、Top訊息 | ✅ |
| 🖥️ **TUI儀表盤** | 終端視覺化介面 | ✅ |
| 📄 **多格式匯出** | 文字、JSON、CSV報告 | ✅ |
| 🔄 **即時跟蹤** | 類似`tail -f`的即時日誌監控 | ✅ |
| 📦 **gzip支援** | 直接讀取壓縮日誌檔案 | ✅ |
### 🚀 快速開始
#### 環境要求
- Python 3.8+
- 作業系統:Linux / macOS / Windows
#### 安裝方式
**方式1:直接下載使用(推薦)**
# 克隆倉庫
git clone https://github.com/gitstq/LogInsight-CLI.git
cd LogInsight-CLI
# 直接使用
python3 loginsight.py --help
**方式2:pip安裝**
pip install loginsight-cli
#### 快速使用
# 分析單個日誌檔案
python3 loginsight.py /var/log/syslog
# 分析多個日誌檔案
python3 loginsight.py *.log
# 即時跟蹤日誌
python3 loginsight.py app.log --follow
# 只顯示錯誤級別及以上
python3 loginsight.py app.log --level ERROR
# 匯出JSON報告
python3 loginsight.py app.log --json -o report.json
# 顯示TUI儀表盤
python3 loginsight.py app.log --dashboard
### 📖 詳細使用指南
請參考 [简体中文](#简体中文) 部分的詳細文檔。
### 📄 開源協議
本專案採用 [MIT License](LICENSE) 開源協議。
## English
### 🎉 Introduction
**LogInsight-CLI** is a zero-dependency, lightweight terminal log intelligent analysis tool designed for developers and DevOps engineers. It quickly parses various log formats, automatically identifies log levels, detects anomaly patterns, and generates intuitive analysis reports.
**Pain Points Solved:**
- ❌ Traditional log analysis tools (like ELK) are complex to deploy and resource-intensive
- ❌ Command-line tools (like grep/awk) have limited functionality and steep learning curves
- ✅ LogInsight-CLI is zero-dependency, ready-to-use, and feature-complete
**Differentiation Highlights:**
- 🚀 **Zero Dependencies**: Pure Python standard library implementation
- 🎯 **Smart Parsing**: Auto-detects multiple timestamp formats and log levels
- 🚨 **Anomaly Detection**: Built-in intelligent algorithms for error rate monitoring
- 📊 **Multi-format Output**: Supports text reports, JSON, and CSV formats
- 🖥️ **TUI Dashboard**: Terminal visualization of analysis results
- 📦 **gzip Support**: Direct analysis of compressed log files
### ✨ Core Features
| Feature | Description | Status |
|---------|-------------|--------|
| 🔍 **Multi-format Parsing** | Supports ISO 8601, standard format, syslog timestamps | ✅ |
| 📊 **5-Level Classification** | DEBUG, INFO, WARNING, ERROR, CRITICAL | ✅ |
| 🚨 **Anomaly Detection** | Error rate monitoring, burst detection, pattern recognition | ✅ |
| 📈 **Statistical Analysis** | Log level distribution, time range, top messages | ✅ |
| 🖥️ **TUI Dashboard** | Terminal visualization interface | ✅ |
| 📄 **Multi-format Export** | Text, JSON, CSV reports | ✅ |
| 🔄 **Real-time Tracking** | `tail -f` like real-time log monitoring | ✅ |
| 📦 **gzip Support** | Direct reading of compressed log files | ✅ |
### 🚀 Quick Start
#### Requirements
- Python 3.8+
- OS: Linux / macOS / Windows
#### Installation
**Option 1: Direct Download (Recommended)**
# Clone repository
git clone https://github.com/gitstq/LogInsight-CLI.git
cd LogInsight-CLI
# Use directly
python3 loginsight.py --help
**Option 2: pip Install**
pip install loginsight-cli
#### Quick Usage
# Analyze single log file
python3 loginsight.py /var/log/syslog
# Analyze multiple log files
python3 loginsight.py *.log
# Real-time log tracking
python3 loginsight.py app.log --follow
# Show only ERROR level and above
python3 loginsight.py app.log --level ERROR
# Export JSON report
python3 loginsight.py app.log --json -o report.json
# Show TUI dashboard
python3 loginsight.py app.log --dashboard
### 📖 Detailed Usage
#### Command Line Arguments
positional arguments:
files Log file paths (supports wildcards and gzip files)
options:
-h, --help Show help message
-f, --follow Follow file changes in real-time (like tail -f)
-l, --level Show only specified level and above
-n, --lines Show only last N lines
--start-time Start time (format: YYYY-MM-DD HH:MM:SS)
--end-time End time (format: YYYY-MM-DD HH:MM:SS)
--pattern Filter logs containing specified pattern
--exclude Exclude logs containing specified pattern
-o, --output Output report to file
--json Output JSON format
--csv Output CSV format
--dashboard Show TUI dashboard
--anomaly-detection Enable anomaly detection (default: on)
#### Typical Use Cases
**Case 1: Troubleshooting Production Issues**
# Analyze error logs from the last hour
python3 loginsight.py /var/log/app.log \
--start-time "2025-01-15 10:00:00" \
--end-time "2025-01-15 11:00:00" \
--level ERROR
**Case 2: Monitor Application Startup**
# Real-time tracking with error highlighting
python3 loginsight.py app.log --follow --level WARNING
**Case 3: Generate Daily Reports**
# Generate JSON format analysis report
python3 loginsight.py /var/log/*.log --json -o daily_report.json
### 💡 Design & Roadmap
#### Technical Choices
- **Pure Python**: Ensures cross-platform compatibility
- **Zero Dependencies**: Low deployment barrier, suitable for containers
- **Modular Architecture**: Easy to extend with new parsers and detection rules
#### Future Roadmap
### 📦 Packaging & Deployment
#### Build Standalone Executable
# Install pyinstaller
pip install pyinstaller
# Build single-file executable
pyinstaller --onefile --name loginsight loginsight.py
# Executable located at dist/loginsight
#### Docker Deployment
FROM python:3.11-slim
WORKDIR /app
COPY loginsight.py .
ENTRYPOINT ["python3", "loginsight.py"]
docker build -t loginsight-cli .
docker run -v /var/log:/logs loginsight-cli /logs/syslog
### 📄 License
This project is licensed under the [MIT License](LICENSE).
*Lightweight Terminal Log Intelligent Analysis Engine* [](https://www.python.org/) [](LICENSE) []() []() [简体中文](#简体中文) | [繁體中文](#繁體中文) | [English](#english)
**Made with ❤️ by LogInsight Team**