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.
- 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.
- Java 8 or later
- Apache Maven
-
Clone the repository:
git clone <repository-url> cd log-analyzer
-
Build the project using Maven:
mvn clean install
-
Run the application:
mvn spring-boot:run
The application will start on port
8080
.
You can use a tool like curl
to interact with the API.
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."
}
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."
}
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."
}