Log Parser
A log parsing and analysis tool for security operations and DevOps.
Features
- - Multi-format Support - nginx, apache, syslog, application logs
- Auto-detection - Automatically detect log format
- Key Extraction - Extract IPs, timestamps, error codes, URLs
- Filtering - Filter logs by IP, status code, time range
- Statistics - Generate summary reports
- Error Detection - Identify and highlight error entries
Usage
CODEBLOCK0
Actions
| Action | Description |
|---|
| INLINECODE0 | Parse log file and extract fields |
| INLINECODE1 |
Generate statistics report |
|
filter | Filter logs by criteria |
|
errors | Extract error entries only |
|
top | Top N items (IPs, URLs, etc.) |
Options
| Option | Type | Default | Description |
|---|
| INLINECODE5 | string | - | Log file path |
| INLINECODE6 |
string | auto | Log format (auto, nginx, apache, syslog) |
|
--limit | int | 100 | Max results to return |
|
--filter-ip | string | - | Filter by IP address |
|
--filter-status | string | - | Filter by status code |
|
--top-field | string | - | Field for top N (ip, url, status) |
Supported Log Formats
nginx
CODEBLOCK1
apache
CODEBLOCK2
syslog
CODEBLOCK3
application logs (JSON)
CODEBLOCK4
Examples
CODEBLOCK5
Use Cases
- 1. Security Analysis - Identify suspicious IPs, failed logins
- Performance Monitoring - Find slow requests, errors
- Traffic Analysis - Top URLs, user agents
- Debugging - Extract error entries quickly
Output Format
All results are returned in JSON format:
CODEBLOCK6
Current Status
In development.
日志解析器
一款用于安全运维和DevOps的日志解析与分析工具。
功能特性
- - 多格式支持 - nginx、apache、syslog、应用程序日志
- 自动检测 - 自动识别日志格式
- 关键信息提取 - 提取IP地址、时间戳、错误码、URL
- 过滤筛选 - 按IP、状态码、时间范围过滤日志
- 统计分析 - 生成汇总报告
- 错误检测 - 识别并高亮错误条目
使用方法
bash
python3 skills/log-parser/scripts/log_parser.py <动作> [选项]
动作列表
| 动作 | 描述 |
|---|
| parse | 解析日志文件并提取字段 |
| stats |
生成统计报告 |
| filter | 按条件过滤日志 |
| errors | 仅提取错误条目 |
| top | 前N项(IP、URL等) |
选项参数
| 选项 | 类型 | 默认值 | 描述 |
|---|
| --file | 字符串 | - | 日志文件路径 |
| --format |
字符串 | auto | 日志格式(auto、nginx、apache、syslog) |
| --limit | 整数 | 100 | 最大返回结果数 |
| --filter-ip | 字符串 | - | 按IP地址过滤 |
| --filter-status | 字符串 | - | 按状态码过滤 |
| --top-field | 字符串 | - | 前N项的字段(ip、url、status) |
支持的日志格式
nginx
192.168.1.1 - - [22/Mar/2026:14:00:00 +0800] GET /api/test HTTP/1.1 200 1234
apache
192.168.1.1 - - [22/Mar/2026:14:00:00 +0800] GET /api/test HTTP/1.1 200 1234
syslog
Mar 22 14:00:00 server sshd[12345]: Failed password for root from 192.168.1.1
应用程序日志(JSON格式)
json
{timestamp: 2026-03-22T14:00:00Z, level: ERROR, message: ...}
使用示例
bash
解析日志文件
python3 skills/log-parser/scripts/log_parser.py parse --file /var/log/nginx/access.log
生成统计信息
python3 skills/log-parser/scripts/log_parser.py stats --file /var/log/nginx/access.log
按IP过滤
python3 skills/log-parser/scripts/log_parser.py filter --file /var/log/nginx/access.log --filter-ip 192.168.1.1
获取前10个IP
python3 skills/log-parser/scripts/log_parser.py top --file /var/log/nginx/access.log --top-field ip --limit 10
提取错误信息
python3 skills/log-parser/scripts/log_parser.py errors --file /var/log/nginx/access.log
应用场景
- 1. 安全分析 - 识别可疑IP、登录失败记录
- 性能监控 - 发现慢请求、错误信息
- 流量分析 - 热门URL、用户代理
- 调试排错 - 快速提取错误条目
输出格式
所有结果以JSON格式返回:
json
{
success: true,
total: 1000,
parsed: 998,
entries: [...],
stats: {...}
}
当前状态
开发中。