Skip to content

A real-time log monitoring and analysis tool that categorizes logs and provides AI-powered insights using Google Gemini API. Supports JSON log storage and real-time file watching.

Notifications You must be signed in to change notification settings

asyncnavi/ai-log-analyzer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI Log Analyzer 📜⚡

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.

📌 Features

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


⚙️ Installation

1️⃣ Clone the Repository

git clone https://github.com/asyncnavi/ai-log-analyzer.git cd ai-log-analyzer

2️⃣ Install Dependencies

Ensure you have Go 1.19+ installed.

go mod tidy

3️⃣ Set Up Environment Variables

Create a .env file in the root directory and add your Google Gemini API Key:

GEMINI_API_KEY=your_gemini_api_key_here

🚀 Usage

1️⃣ Start Watching Logs

go run main.go This will start monitoring `logs.txt` in real-time.

2️⃣ Analyze Logs Manually

You can manually analyze a log entry: logutils.LogAnalyzer("ERROR: Database connection failed")

3️⃣ View Saved Logs

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." } ]


📖 API Reference

🔹 func LogAnalyzer(logMessage string)

  • Description: Categorizes logs and analyzes errors with AI.
  • Parameters: logMessage (string) – The log entry to process.
  • Example: logutils.LogAnalyzer("WARNING: High memory usage detected")

🔹 func SaveLogEntry(entry LogEntry)

  • 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)

🔹 func WatchLogs(filepath string)

  • Description: Continuously monitors a log file for new entries.
  • Parameters: filepath (string) – Path to the log file.
  • Example: go logutils.WatchLogs("logs.txt")

🛠️ Project Structure

/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

📜 License

This project is open-source and licensed under the MIT License.

About

A real-time log monitoring and analysis tool that categorizes logs and provides AI-powered insights using Google Gemini API. Supports JSON log storage and real-time file watching.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages