# intelligent-log-analyzer **Repository Path**: jerris-code-space/intelligent-log-analyzer ## Basic Information - **Project Name**: intelligent-log-analyzer - **Description**: 一款使用 LangChainGo 库开发的智能日志分析器命令行工具。 - **Primary Language**: Go - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-02-16 - **Last Updated**: 2026-04-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Intelligent Log Analyzer An intelligent log analysis tool built with Go, supporting multi-format log parsing, error pattern recognition, anomaly detection, and AI-driven deep analysis. ## Features - **Multi-format Log Parsing**: Automatically parses JSON and structured logs - **Intelligent Log Level Identification**: Automatically infers log levels (INFO, WARN, ERROR, etc.) - **Error Pattern Detection**: Automatically discovers and categorizes common error patterns - **Anomaly Detection**: Identifies anomalous behaviors and outliers in logs - **AI Deep Analysis**: Integrates AI capabilities for semantic log analysis - **Visualized Reporting**: Generates structured analysis reports - **Flexible Configuration**: Supports YAML configuration files to customize analysis behavior ## Project Structure ``` intelligent-log-analyzer/ ├── main.go # Program entry point ├── config.go # Configuration management module ├── model.go # Core data structures and analysis logic ├── util.go # Utility functions ├── config-example.yml # Configuration file example ├── sample.log # Sample log file └── go.mod # Go module definition ``` ## Quick Start ### Prerequisites - Go 1.16 or higher - Valid AI API configuration (e.g., OpenAI API Key) ### Build and Install ```bash # Clone the project git clone https://gitee.com/jerris-code-space/intelligent-log-analyzer.git cd intelligent-log-analyzer # Build the project go build -o log-analyzer . # Or run directly go run main.go ``` ### Configuration 1. Copy the configuration example: ```bash cp config-example.yml config.yml ``` 2. Edit `config.yml` to set up AI API configurations. 3. Run the analysis: ```bash ./log-analyzer -config config.yml ``` ## Usage ### Command-line Arguments ```bash ./log-analyzer [OPTIONS] ``` ### Configuration File Example (config-example.yml) ```yaml # AI Analysis Configuration ai: api_key: "your-api-key" endpoint: "https://api.example.com/v1" model: "gpt-3.5-turbo" # Analysis Configuration analysis: # Log level keywords log_levels: - "INFO" - "WARN" - "ERROR" - "DEBUG" - "FATAL" # Anomaly detection threshold anomaly_threshold: 0.8 # Maximum concurrency max_concurrency: 4 # Output Configuration output: format: "json" # json or text verbose: false ``` ### Supported Log Formats The tool supports the following log formats: **JSON Format:** ```json {"timestamp": "2024-01-15T10:30:00Z", "level": "ERROR", "message": "Database connection failed", "service": "api-gateway"} ``` **Structured Log Format:** ``` [2024-01-15 10:30:00] [ERROR] Database connection failed - service: api-gateway ``` ## Core API ### LogAnalyzer The main analyzer struct, providing the following methods: - `NewLogAnalyzer() (*LogAnalyzer, error)` - Creates a new analyzer instance - `ParseLogFile(filename string) ([]LogEntry, error)` - Parses a log file - `AnalyzeLogs(entries []LogEntry) (*LogAnalysis, error)` - Executes log analysis - `PrintReport()` - Prints the analysis report ### Data Models - `LogEntry` - Single log entry - `LogAnalysis` - Complete analysis result - `ErrorPattern` - Error pattern information - `Anomaly` - Anomaly detection result - `TimeRange` - Time range definition ## Sample Output ``` === Log Analysis Report === Time Range: 2024-01-15 10:00:00 ~ 2024-01-15 11:00:00 Log Statistics: Total Logs: 1,234 INFO: 1,000 (81%) WARN: 150 (12%) ERROR: 84 (7%) Error Patterns: 1. Database connection failed (45 occurrences) 2. Timeout waiting for response (23 occurrences) 3. Null pointer exception (12 occurrences) Anomaly Detection: - 3 anomalous time points detected - Anomaly type: Sudden spike in errors AI Analysis Suggestions: Prioritize investigating database connection pool configuration issues ``` ## Contributing 1. Fork the project 2. Create a feature branch (`git checkout -b feature/amazing-feature`) 3. Commit your changes (`git commit -m 'Add amazing feature'`) 4. Push to the branch (`git push origin feature/amazing-feature`) 5. Create a Pull Request ## License This project is open-sourced under the MIT License. ## Frequently Asked Questions **Q: What log formats are supported?** A: Currently supports JSON format and common structured log formats. **Q: Is an API Key required for AI analysis?** A: Yes, a valid AI service API Key must be configured. **Q: How are large log files handled?** A: The tool automatically processes logs in batches; concurrency can be configured via the config file. **Q: Can I customize log level detection rules?** A: Yes, you can define custom log level keywords in the configuration file.