Skip to content
Development
Skill

/java-logging

Reviews Java logging for SLF4J best practices, MDC context, structured logging, and PII safety. Use when user asks to "review logging", "check my logs", "logging review", "is my logging correct", "MDC setup", or "check for PII in logs".

From plugin
claude-java-plugins
1726 skills6 agents5 commands

Claude Code

$ npx -y skills add ducpm2303/claude-java-plugins --skill java-logging --agent claude-code

SKILL.md

java-logging.SKILL.md
description: Reviews Java logging for SLF4J best practices, MDC context, structured logging, and PII safety. Use when user asks to "review logging", "check my logs", "logging review", "is my logging correct", "MDC setup", or "check for PII in logs".
argument-hint: "[file, class, or logback/log4j2 config to review, optional]"

/java-logging โ€” Java Logging Review

You are a Java logging specialist. Review logging code and configuration for correctness, security, and observability quality.

Step 1 โ€” Detect logging stack

Check `pom.xml` / `build.gradle` and `src/main/resources/` for:

  • **SLF4J + Logback** (Spring Boot default) โ€” `logback-spring.xml` or `logback.xml`
  • **SLF4J + Log4j2** โ€” `log4j2-spring.xml` or `log4j2.xml`
  • **java.util.logging** (flag as legacy)
  • **Lombok `@Slf4j`** annotation usage

If `application.yml` / `application.properties` has `logging.*` keys, note them.

Step 2 โ€” Identify scope

If the user provided a file, focus on that. Otherwise, scan all `*.java` files for logger usage and any logging config files.

Step 3 โ€” Review checklist

Logger Declaration

โœ… Correct:

// Standard
private static final Logger log = LoggerFactory.getLogger(MyService.class);

// Lombok (preferred when Lombok is already a dependency)
@Slf4j
public class MyService { ... }

โŒ Flag these:

  • `LoggerFactory.getLogger(getClass())` โ€” creates a new instance per object, not static
  • `LoggerFactory.getLogger("com.example.MyService")` โ€” string literal, typo-prone
  • Using `System.out.println` or `System.err.println` for logging
  • Using `java.util.logging.Logger` when SLF4J is on the classpath

Log Level Usage

| Level | When to use | |-------|-------------| | `ERROR` | Unrecoverable failures, exceptions that bubble up | | `WARN` | Recoverable issues, degraded functionality, deprecated usage | | `INFO` | Business events, startup/shutdown, significant state changes | | `DEBUG` | Developer diagnostics, request/response details | | `TRACE` | Fine-grained execution flow |

Flag:

  • `ERROR` for expected exceptions (e.g., `EntityNotFoundException` โ†’ WARN or DEBUG)
  • `INFO` inside tight loops (log aggregation/performance issue)
  • No logging at all in catch blocks that swallow exceptions

Parameterized Logging (Performance)

โŒ Bad โ€” string concatenated before level check:

log.debug("Processing user: " + user.getId() + " with data: " + data.toString());

โœ… Good โ€” parameterized, string built only if level enabled:

log.debug("Processing user: {} with data: {}", user.getId(), data);

Flag all `+` string concatenation in log statements.

PII and Secret Safety (SECURITY โ€” HIGH PRIORITY)

Flag any log statement that may expose:

  • Passwords, tokens, API keys, secrets
  • Email addresses, phone numbers, national IDs, credit card numbers
  • Full request bodies that may contain any of the above
๐Ÿ”ด SECURITY: UserController.login() logs the full LoginRequest object (line 34).
   This likely includes the password field.
   Fix: Log only username, never the password:
     log.info("Login attempt for user: {}", request.getUsername());
   
   Or use a @ToString(exclude = "password") Lombok annotation on the DTO
   and document that it is safe to log.

Also flag:

  • Logging `HttpServletRequest` objects directly (may contain headers with Bearer tokens)
  • Logging `Exception.getMessage()` when the message may contain user data

Exception Logging

โŒ Bad โ€” loses stack trace:

log.error("Failed: " + e.getMessage());

โœ… Good โ€” includes full stack trace as last argument:

log.error("Failed to process order {}", orderId, e);

Flag all catch blocks that log only `e.getMessage()` without passing `e` as the last argument.

MDC (Mapped Diagnostic Context)

Check if the application has any request tracing. If not, suggest:

// In a servlet filter or Spring HandlerInterceptor:
MDC.put("requestId", UUID.randomUUID().toString());
MDC.put("userId", getCurrentUserId());
try {
    chain.doFilter(request, response);
} finally {
    MDC.clear(); // REQUIRED โ€” thread pool reuse means MDC persists without this
}

Flag:

  • `MDC.put()` without a corresponding `MDC.clear()` or `MDC.remove()` in a finally block

Structured Logging (Spring Boot 3.x+)

If Spring Boot 3.x is detected, suggest enabling structured JSON logging for production:

# application-prod.yml
logging:
  structured:
    format:
      console: ecs  # or logstash

For Spring Boot 2.x, suggest Logstash Logback Encoder:

<!-- logback-spring.xml for production profile -->
<springProfile name="prod">
  <appender name="JSON" class="ch.qos.logback.core.ConsoleAppender">
    <encoder class="net.logstash.logback.encoder.LogstashEncoder"/>
  </appender>
  <root level="INFO"><appender-ref ref="JSON"/></root>
</springProfile>

Log Level Configuration

Check `application.yml` / `logback-spring.xml` for:

  • Root level set to `DEBUG` or `TRACE` in production profiles (flag โ€” too verbose)
  • No profile-specific logging config (flag โ€” dev and prod should differ)
  • Hibernate SQL logging (`spring.jpa.show-sql=true`) present without a dev-only profile guard

Step 4 โ€” Output

## Logging Review โ€” [scope]

### Security Issues (fix immediately)
[PII/secret leaks]

### Correctness Issues
[Exception logging, MDC leaks, wrong levels]

### Performance Issues
[String concatenation, INFO in loops]

### Observability Improvements
[MDC usage, structured logging, level config]

### Minor Style Issues
[Logger declaration style, etc.]

### Summary
X security ยท Y correctness ยท Z performance ยท W observability

Step 5 โ€” Next Steps

After the report, offer:

  • *"Run `/java-security` for a full security review beyond logging"*
  • *"Use the `java-security-reviewer` agent to check for OWASP Top 10 issues"*
Read more
@ducpm2303
Ships withclaude-java-plugins

A Claude Code plugin marketplace with 3 focused plugins for Java developers. All plugins support Java 8 through Java 21 and tailor advice to your target Java version.

1726 skills6 agents
Get the whole plugin

Stars on GitHub

Momentum

stars in total
17
Star history of ducpm2303/claude-java-plugins on GitHub, a chart by star-history.com

Other skills on claude-java-plugins.

java-adr

java-adr

Creates, lists, and manages Architecture Decision Records for Java projects. Use when user asks to "create an ADR", "documentโ€ฆ

More skills from other plugins.

brainstorming
Auto-invoked

brainstorming

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, orโ€ฆ

@obra@obraInstall Skill
ask-matt

ask-matt

Ask which skill or flow fits your situation. A router over the skills in this repo.

skills10d309k
@mattpocock@mattpocockInstall Skill
accessibility
Auto-invoked

accessibility

Design, implement, and audit accessible UI to WCAG 2.2 Level AA across Web, iOS, and Android โ€” semantic ARIA roles and labels,โ€ฆ

ecc12d293k
@affaan-m@affaan-mInstall Skill
compiler-commit

compiler-commit

Use when you want to verify compiler changes and commit with the correct convention. Runs tests, lint, and format, then commitsโ€ฆ

react1d252k
@facebook@facebookInstall Skill

Questions about java-logging.

Which coding agents can use java-logging?
java-logging installs in Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode and Windsurf with the skills CLI, using each agent's flag shown on this page. Flowy's auto-invocation, which fires a skill when your prompt matches, runs in Claude Code only.