惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
V
V2EX
博客园 - 【当耐特】
WordPress大学
WordPress大学
爱范儿
爱范儿
美团技术团队
宝玉的分享
宝玉的分享
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
小众软件
小众软件
量子位
Hugging Face - Blog
Hugging Face - Blog
B
Blog RSS Feed
Recorded Future
Recorded Future
Engineering at Meta
Engineering at Meta
雷峰网
雷峰网
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
M
MIT News - Artificial intelligence
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 聂微东
H
Hackread – Cybersecurity News, Data Breaches, AI and More
腾讯CDC
大猫的无限游戏
大猫的无限游戏
Jina AI
Jina AI
博客园 - 叶小钗
GbyAI
GbyAI
Y
Y Combinator Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
F
Full Disclosure
G
Google Developers Blog
D
Docker
T
Tailwind CSS Blog
C
Check Point Blog
Last Week in AI
Last Week in AI
人人都是产品经理
人人都是产品经理
T
The Blog of Author Tim Ferriss
B
Blog
博客园 - 三生石上(FineUI控件)
博客园 - Franky
H
Help Net Security
MyScale Blog
MyScale Blog
U
Unit 42
D
DataBreaches.Net
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
I
InfoQ
阮一峰的网络日志
阮一峰的网络日志
The GitHub Blog
The GitHub Blog
L
LangChain Blog
有赞技术团队
有赞技术团队
Martin Fowler
Martin Fowler
Microsoft Security Blog
Microsoft Security Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
Turning Server Logs into Incident Summaries with Java and Groq
Misbah Ulhaq · 2026-05-06 · via DEV Community

I built a small Java CLI that uses Groq’s LLM API to turn noisy server logs into structured incident summaries: root cause, severity, affected components, and suggested fixes.

Introduction

Server logs are useful, but during an incident they can also become overwhelming.

A single failure can produce hundreds or thousands of lines in a few minutes. You search for ERROR, skim stack traces, follow timestamps, jump between services, and slowly piece together what actually happened.

The problem is not that logs are useless. The problem is that logs are raw events, not explanations.

I built ai-log-analyzer to explore a simple idea:

Can a Java CLI turn noisy server logs into a short, structured incident summary using an LLM?

This is not meant to replace observability platforms, incident response workflows, or proper monitoring. It is a small developer tool that shows how LLMs can help summarize unstructured operational data.

The goal was simple:

  • Input: a plain-text log file
  • Processing: split the file into LLM-friendly chunks
  • Output: root cause, severity, affected components, fix suggestions, and summary
  • Constraint: keep the setup minimal and easy to run locally

The Problem: Logs Are Events, Not Intelligence

Here is a familiar debugging flow:

  1. A service starts failing.
  2. You open the logs.
  3. You see a wall of timestamps, warnings, retries, and stack traces.
  4. You grep for ERROR.
  5. You still have to figure out which event actually matters.

Logs tell you what happened. They do not always tell you why it happened or what to do next.

That analysis still lands on the engineer.

This project tries to reduce that manual step. Instead of reading every line yourself, the tool sends chunks of logs to an LLM and asks for a structured analysis.


Architecture

The architecture is intentionally small.

The project has three main pieces:

  1. LogChunker — reads the log file and breaks it into smaller chunks
  2. GroqClient — sends each chunk to Groq’s API and parses the response
  3. AnalysisResult — stores the structured result returned by the model

Why Groq?

Groq has a straightforward API, low-latency inference, and easy access to models like llama-3.3-70b-versatile. For this project, I wanted something simple enough to call from a Java CLI without adding unnecessary infrastructure.

Why Java 21 HttpClient?

Java 21’s built-in HttpClient is good enough for this use case. I did not want to add an external HTTP dependency just to make one API call.

Why Maven Shade?

The Maven Shade plugin produces a single executable JAR. That makes the tool easy to build and run without classpath issues.


Project Structure

java-ai-log-analyzer/
├── pom.xml
├── README.md
├── sample-logs/
│   └── app.log
└── src/main/java/com/mulhaq/loganalyzer/
    ├── LogAnalyzer.java      # main entry point and CLI handling
    ├── GroqClient.java       # Groq API calls
    ├── LogChunker.java       # reads and chunks log files
    └── AnalysisResult.java   # structured analysis result

Enter fullscreen mode Exit fullscreen mode


Stack and Tooling

The project uses:

  • Java 21
  • Maven
  • Jackson for JSON parsing
  • Groq API
  • Maven Shade plugin for a runnable JAR

The build command is:

mvn clean package

Enter fullscreen mode Exit fullscreen mode

The output is:

target/java-ai-log-analyzer-1.0-shaded.jar

Enter fullscreen mode Exit fullscreen mode


Key Implementation Pieces

1. LogChunker: Splitting the Log File

LLMs have context limits, so the tool does not send the entire log file in one request. It splits the file into smaller chunks.

public class LogChunker {
    private static final int CHUNK_SIZE = 3000;

    public static List<String> chunkLogFile(String filePath) throws Exception {
        String content = Files.readString(Paths.get(filePath));
        List<String> chunks = new ArrayList<>();
        int length = content.length();

        for (int i = 0; i < length; i += CHUNK_SIZE) {
            int end = Math.min(i + CHUNK_SIZE, length);
            chunks.add(content.substring(i, end));
        }

        return chunks;
    }
}

Enter fullscreen mode Exit fullscreen mode

The current version uses a simple character-based chunking strategy. It works for a prototype, but a production version should be smarter: chunk by timestamp ranges, request boundaries, stack traces, or service sections.


2. GroqClient: Calling the LLM API

The GroqClient sends each chunk to Groq and asks for a structured JSON response.

public class GroqClient {
    private static final String API_URL = "https://api.groq.com/openai/v1/chat/completions";
    private static final String MODEL = "llama-3.3-70b-versatile";

    private final String apiKey;
    private final HttpClient httpClient;
    private final ObjectMapper mapper;

    public AnalysisResult analyzeChunk(String logChunk) throws Exception {
        String prompt = "Analyze this server log chunk and provide: root cause, "
                + "affected components, severity (critical/high/medium/low), fix suggestions, "
                + "and a summary. Return as JSON with keys: rootCause, affectedComponents, "
                + "severity, fixSuggestions, summary.\n\nLog:\n" + logChunk;

        String requestBody = mapper.writeValueAsString(Map.of(
                "model", MODEL,
                "messages", List.of(Map.of("role", "user", "content", prompt)),
                "temperature", 0.3
        ));

        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create(API_URL))
                .header("Authorization", "Bearer " + apiKey)
                .header("Content-Type", "application/json")
                .POST(HttpRequest.BodyPublishers.ofString(requestBody))
                .build();

        HttpResponse<String> response = httpClient.send(
                request,
                HttpResponse.BodyHandlers.ofString()
        );

        if (response.statusCode() != 200) {
            throw new RuntimeException("Groq API error: " + response.statusCode());
        }

        var responseJson = mapper.readTree(response.body());
        String content = responseJson.get("choices")
                .get(0)
                .get("message")
                .get("content")
                .asText();

        return mapper.readValue(content, AnalysisResult.class);
    }
}

Enter fullscreen mode Exit fullscreen mode

One practical lesson from this build: model names can change.

I originally used llama3-8b-8192, but that model was later unavailable. I switched to llama-3.3-70b-versatile, and the output quality improved. In a real tool, I would make the model configurable instead of hardcoding it.


3. AnalysisResult: Structuring the Output

The model response is parsed into a simple Java object.

public class AnalysisResult {
    @JsonProperty("rootCause")
    public String rootCause;

    @JsonProperty("affectedComponents")
    public List<String> affectedComponents;

    @JsonProperty("severity")
    public String severity;

    @JsonProperty("fixSuggestions")
    public List<String> fixSuggestions;

    @JsonProperty("summary")
    public String summary;
}

Enter fullscreen mode Exit fullscreen mode

This keeps the CLI output predictable and easier to consume later if I want to write results to JSON, Markdown, or another system.


4. LogAnalyzer: The CLI Entry Point

The main class reads the API key, chunks the log file, sends each chunk to Groq, and prints the analysis.

public class LogAnalyzer {
    public static void main(String[] args) throws Exception {
        if (args.length == 0) {
            System.err.println("Usage: java -jar java-ai-log-analyzer-1.0-shaded.jar <log-file>");
            System.exit(1);
        }

        String apiKey = System.getenv("GROQ_API_KEY");
        if (apiKey == null || apiKey.isEmpty()) {
            System.err.println("Error: GROQ_API_KEY environment variable not set.");
            System.exit(1);
        }

        List<String> chunks = LogChunker.chunkLogFile(args[0]);
        GroqClient client = new GroqClient(apiKey);

        System.out.println("=== AI-Powered Log Analyzer ===\n");
        System.out.println("Log file: " + args[0]);
        System.out.println("Total chunks: " + chunks.size() + "\n");

        for (int i = 0; i < chunks.size(); i++) {
            System.out.println("--- Chunk " + (i + 1) + " of " + chunks.size() + " ---");

            AnalysisResult result = client.analyzeChunk(chunks.get(i));

            System.out.println("Root Cause: " + result.rootCause);
            System.out.println("Severity: " + result.severity);
            System.out.println("Affected Components:");
            result.affectedComponents.forEach(c -> System.out.println(" - " + c));
            System.out.println("Fix Suggestions:");
            result.fixSuggestions.forEach(s -> System.out.println(" - " + s));
            System.out.println("Summary: " + result.summary + "\n");
        }

        System.out.println("=== Analysis Complete ===");
    }
}

Enter fullscreen mode Exit fullscreen mode


Example Output

I ran it against a small sample log file included in the repo.

=== AI-Powered Log Analyzer ===
Log file: sample-logs/app.log
File size: 3.70 KB
Reading and chunking log file...
Total chunks: 2

--- Chunk 1 of 2 ---
Root Cause: Database connection pool exhaustion due to prolonged request processing
Severity: critical
Affected Components:
 - DatabasePool
 - AuthService
 - CacheManager
 - DataSyncService
 - ApiGateway
 - RequestHandler
Fix Suggestions:
 - Increase the database connection pool size
 - Optimize database queries to reduce connection usage
 - Implement connection timeout and retry mechanisms
 - Monitor and alert on connection pool utilization
 - Regularly check for and resolve data inconsistencies
Summary: The application experienced a critical outage due to database connection pool exhaustion. Requests were queued and timed out as new connections could not be established.

--- Chunk 2 of 2 ---
Root Cause: Unknown, but a repair was initiated
Severity: low
Affected Components:
 - Database
 - Connection Pool
 - Cache Cluster
 - Request Handler
 - Data Sync Service
Fix Suggestions:
 - Monitor system logs for similar issues
 - Verify database consistency regularly
 - Review connection pool and cache cluster configurations
Summary: The system experienced an issue requiring a database consistency repair. Repair was successful and all components are now fully operational.

=== Analysis Complete ===

Enter fullscreen mode Exit fullscreen mode

That is the main value of this project: noisy logs become a short, structured incident summary.

It is not perfect, but it gives an engineer a faster starting point.


Privacy Note

Logs can contain sensitive information: tokens, emails, customer IDs, internal URLs, stack traces, headers, and infrastructure details.

Before sending logs to any external LLM API, scrub sensitive data.

For a production-grade version, I would add a redaction layer before the API call. That layer should remove or mask:

  • API keys
  • access tokens
  • emails
  • IP addresses where needed
  • customer identifiers
  • internal service URLs
  • request headers
  • personally identifiable information

This project should be treated as a local developer prototype unless proper redaction and security controls are added.


Limitations

This is not a replacement for a full observability pipeline.

A few limitations are worth calling out:

  • The analyzer depends on the quality of the model response.
  • It processes chunks independently, so cross-chunk reasoning is limited.
  • The current version does not deduplicate repeated errors.
  • It does not validate every model response against a strict schema before parsing.
  • Very large logs should be pre-filtered or split before analysis.
  • The chunking strategy is simple and may split related events across chunks.
  • Sensitive logs should be scrubbed before being sent to an external API.

For a production version, I would add structured validation, retries, redaction, aggregation across chunks, and better error handling.


How to Run It Yourself

Prerequisites

  • Java 21
  • Maven 3.8+
  • Groq API key from console.groq.com

Steps

# 1. Set your API key
export GROQ_API_KEY="your-api-key-here"

# 2. Clone the repo
git clone https://github.com/mulhaq/blogs
cd blogs/java-ai-log-analyzer

# 3. Build
mvn clean package

# 4. Run against the sample log
java -jar target/java-ai-log-analyzer-1.0-shaded.jar sample-logs/app.log

# 5. Optional: save output to a file
java -jar target/java-ai-log-analyzer-1.0-shaded.jar sample-logs/app.log > analysis.txt

Enter fullscreen mode Exit fullscreen mode

Common Issues

GROQ_API_KEY not found

Make sure the variable is exported in your current shell session.

Connection timeout

You may be hitting rate limits or network issues. Wait and retry.

Out of memory on huge files

Pre-split large logs before analysis:

split -l 1000 app.log app-log-part-

Enter fullscreen mode Exit fullscreen mode

Then analyze each batch separately.


What I Would Improve Next

There are several directions I would take this project next.

1. Smarter Chunking

Instead of splitting every 3000 characters, chunk logs by timestamp, request ID, trace ID, or stack trace boundary.

2. Aggregated Summary

Right now each chunk is analyzed separately. A better version would produce a final summary across all chunks.

3. Redaction Layer

Before calling the LLM API, detect and mask secrets, emails, tokens, and internal identifiers.

4. Schema Validation

The model is asked to return JSON, but production code should validate and repair malformed responses.

5. Streaming Mode

A future version could tail a live log file and analyze new chunks as they arrive.

6. Observability Integrations

The results could be sent to tools like Grafana Loki, Datadog, Slack, or PagerDuty.

7. Custom Severity Rules

Different teams define severity differently. A config file could let teams define what critical, high, or medium means in their environment.


Conclusion

Logs are one of the most valuable sources of operational truth, but they are not always easy to reason about during an incident.

This project is a small experiment in using LLMs as a debugging assistant. The LLM does not replace engineering judgment, but it can help summarize noisy logs, identify likely causes, and suggest starting points for investigation.

The broader pattern is useful:

Find a repetitive engineering task, wrap it in a small tool, and use an LLM to reduce the manual analysis step.

Logs are one example. The same pattern could apply to exception traces, failed CI logs, pull request diffs, incident notes, or deployment summaries.

For me, the value is not just the tool itself. It is the workflow: take a common engineering pain point, build a focused implementation, test it on a realistic input, document the tradeoffs, and keep improving it.


Full source code: https://github.com/mulhaq/blogs/tree/main/java-ai-log-analyzer

Tags: #java #ai #groq #devtools