logging-patterns

Implements structured JSON logging with SLF4J and MDC for Java applications.

Updated Dec 23, 2025
One-click install
npx skills add https://github.com/zuldare/apuntesIA --skill logging-patterns-zuldare
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: logging-patterns
Source: https://github.com/zuldare/apuntesIA/tree/main/skills/logging-patterns
Command: npx skills add https://github.com/zuldare/apuntesIA --skill logging-patterns-zuldare

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Java applications often produce unstructured text logs that are hard to parse, filter, and analyze, especially when debugging request flows or feeding logs to AI assistants. This Skill provides proven patterns for structured JSON logging, request tracing with correlation IDs, and profile-based log format switching. ## Core Features & Use Cases - Structured JSON Logging: Configure Spring Boot 3.4+ native structured logging (logstash, ecs, gelf formats) or Logstash Logback Encoder for older versions. - Request Tracing with MDC: Add requestId, traceId, and custom fields to every log entry so you can follow a single request through the entire application flow. - AI-Friendly Log Formats: Emit logs that AI tools like Claude Code can parse directly with jq queries, reducing token usage and interpretation errors. - Use Case: You need to debug why an order failed in production. With JSON logs and requestId tracing, you run cat app.log | jq 'select(.requestId == "req-abc123")' and instantly see every step, duration, and error for that request. ## Quick Start Ask the AI to set up structured JSON logging with request tracing in your Spring Boot application using the logging patterns skill.

Frequently Asked Questions about logging-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up JSON logging in Spring Boot?▼

Spring Boot 3.4+ supports structured logging natively via the logging.structured.format.console property set to logstash, ecs, or gelf in application.yml. For older versions, add the logstash-logback-encoder dependency and configure a LogstashEncoder appender in logback-spring.xml.

How to add request ID tracing to Java logs with MDC?▼

Use SLF4J's MDC to store a requestId at the start of each request, then include it in your encoder configuration with includeMdcKeyName. Every log entry in that thread automatically carries the requestId, letting you filter all logs for a single request.

Logstash encoder vs Spring Boot native structured logging?▼

Spring Boot 3.4+ native structured logging requires no extra dependencies and supports logstash, ecs, and gelf formats. The logstash-logback-encoder library is needed for Spring Boot versions below 3.4 or when you need advanced customization of JSON output.

Why is JSON logging better than plain text for debugging?▼

JSON logs allow direct field access with tools like jq instead of regex parsing of text patterns. Fields like level, requestId, and duration_ms can be filtered precisely, and AI assistants parse structured fields faster with lower token usage.

Can I switch between JSON and human-readable logs in Spring Boot?▼

Yes, use Spring profiles to switch formats. Define a json-logs profile with structured console format as default, and a human-logs profile with a pattern-based console layout, then activate with -Dspring.profiles.active=human-logs.