AI Log Analyzer is a Golang-based real-time log monitoring and analysis tool that categorizes logs (INFO
, WARNING
, ERROR
) and leverages Google Gemini AI to provide insights on errors.
✅ Real-time log monitoring
✅ Automatic log categorization (INFO
, WARNING
, ERROR
)
✅ AI-powered insights for ERROR logs using Google Gemini API
✅ JSON log storage with structured formatting
✅ Modular and extensible architecture
git clone https://github.com/asyncnavi/ai-log-analyzer.git cd ai-log-analyzer
Ensure you have Go 1.19+ installed.
go mod tidyCreate a .env
file in the root directory and add your Google Gemini API Key:
go run main.go This will start monitoring `logs.txt` in real-time.
You can manually analyze a log entry: logutils.LogAnalyzer("ERROR: Database connection failed")
All logs are stored in logs.json
in structured JSON format.
Example: [ { "timestamp": "2025-03-19T12:00:00Z", "level": "ERROR", "message": "Database connection failed", "insight": "Check database credentials and network connectivity." } ]
- Description: Categorizes logs and analyzes errors with AI.
- Parameters:
logMessage
(string) – The log entry to process. - Example: logutils.LogAnalyzer("WARNING: High memory usage detected")
- Description: Saves a log entry to
logs.json
. - Parameters:
entry
(LogEntry struct) – The structured log data. - Example: entry := LogEntry{ Timestamp: time.Now().Format(time.RFC3339), Level: "ERROR", Message: "Server timeout", } logutils.SaveLogEntry(entry)
- Description: Continuously monitors a log file for new entries.
- Parameters:
filepath
(string) – Path to the log file. - Example: go logutils.WatchLogs("logs.txt")
/ai-log-analyzer
│── /ai
│ ├── ai.go # AI-powered log analysis
│── /logutils
│ ├── log_handler.go # Log analysis & storage
│── .env # API Key Configuration
│── logs.txt # Example log file (monitored in real-time)
│── logs.json # Structured log storage
│── main.go # Application entry point
│── go.mod # Dependencies
This project is open-source and licensed under the MIT License.