Skip to content

gitkenan/log-analyzer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Log Analyzer Microservice

This is a simple Spring Boot microservice that provides a REST endpoint to analyze raw log strings and return an AI-generated summary of the key issues.

Features

  • REST Endpoint: A single POST /analyze-log endpoint.
  • JSON Payload: Accepts and returns JSON.
  • AI-Powered Analysis: Simulates an AI analysis of log data (currently mocked).
  • Error Handling: Provides meaningful error messages for invalid requests.
  • Unit Tested: Includes unit tests for the service and controller layers.

Prerequisites

  • Java 8 or later
  • Apache Maven

How to Build and Run

  1. Clone the repository:

    git clone <repository-url>
    cd log-analyzer
  2. Build the project using Maven:

    mvn clean install
  3. Run the application:

    mvn spring-boot:run

    The application will start on port 8080.

Example Usage

You can use a tool like curl to interact with the API.

Example 1: NullPointerException

Request:

curl -X POST http://localhost:8080/analyze-log \
-H "Content-Type: application/json" \
-d '{
  "logContent": "2025-06-10 14:32:01.123 ERROR [main] com.example.app.Processor - Unexpected error occurred\njava.lang.NullPointerException: Cannot invoke \"String.length()\" because \"s\" is null\n\tat com.example.app.Processor.process(Processor.java:42)"
}'

Response:

{
  "mainError": "java.lang.NullPointerException",
  "probableCause": "A variable was accessed before it was assigned an object.",
  "suggestedFix": "Ensure all objects are initialized before use. Check the stack trace for the exact line number."
}

Example 2: SQL Exception

Request:

curl -X POST http://localhost:8080/analyze-log \
-H "Content-Type: application/json" \
-d '{
  "logContent": "2025-06-10 15:01:05.567 ERROR [task-executor-1] o.h.e.j.s.SqlExceptionHelper - Connection refused\njava.sql.SQLException: Connection refused\n\tat com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)"
}'

Response:

{
  "mainError": "java.sql.SQLException: Connection refused",
  "probableCause": "The database server is either not running or is blocking the connection.",
  "suggestedFix": "Verify that the database is running and accessible. Check firewall rules and database connection strings."
}

Example 3: Invalid Request (Blank Log Content)

Request:

curl -X POST http://localhost:8080/analyze-log \
-H "Content-Type: application/json" \
-d '{
  "logContent": ""
}'

Response (HTTP 400 Bad Request):

{
  "error": "Log content cannot be blank."
}

About

Get AI-generated summaries of your log files

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages