logback

Logback - Quick Reference

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "logback" with this command: npx skills add claude-dev-suite/claude-dev-suite/claude-dev-suite-claude-dev-suite-logback

Logback - Quick Reference

When to Use This Skill

  • Configure logging in Spring Boot/Java applications

  • File appender with rotation

  • High-performance async logging

Deep Knowledge: Use mcp__documentation__fetch_docs with technology: logback for comprehensive documentation.

Configuration

logback-spring.xml (Spring Boot)

<?xml version="1.0" encoding="UTF-8"?> <configuration> <include resource="org/springframework/boot/logging/logback/defaults.xml"/>

&#x3C;property name="LOG_PATH" value="${LOG_PATH:-logs}"/>
&#x3C;property name="LOG_FILE" value="${LOG_FILE:-app}"/>

&#x3C;!-- Console Appender -->
&#x3C;appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
    &#x3C;encoder>
        &#x3C;pattern>%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}&#x3C;/pattern>
    &#x3C;/encoder>
&#x3C;/appender>

&#x3C;!-- Rolling File Appender -->
&#x3C;appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    &#x3C;file>${LOG_PATH}/${LOG_FILE}.log&#x3C;/file>
    &#x3C;rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
        &#x3C;fileNamePattern>${LOG_PATH}/${LOG_FILE}.%d{yyyy-MM-dd}.%i.log.gz&#x3C;/fileNamePattern>
        &#x3C;maxFileSize>100MB&#x3C;/maxFileSize>
        &#x3C;maxHistory>30&#x3C;/maxHistory>
        &#x3C;totalSizeCap>3GB&#x3C;/totalSizeCap>
    &#x3C;/rollingPolicy>
    &#x3C;encoder>
        &#x3C;pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n&#x3C;/pattern>
    &#x3C;/encoder>
&#x3C;/appender>

&#x3C;!-- Async Appender -->
&#x3C;appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
    &#x3C;appender-ref ref="FILE"/>
    &#x3C;queueSize>512&#x3C;/queueSize>
    &#x3C;discardingThreshold>0&#x3C;/discardingThreshold>
&#x3C;/appender>

&#x3C;!-- Logger Configuration -->
&#x3C;logger name="com.myapp" level="DEBUG"/>
&#x3C;logger name="org.springframework" level="INFO"/>
&#x3C;logger name="org.hibernate.SQL" level="DEBUG"/>

&#x3C;root level="INFO">
    &#x3C;appender-ref ref="CONSOLE"/>
    &#x3C;appender-ref ref="ASYNC"/>
&#x3C;/root>

&#x3C;!-- Profile-specific -->
&#x3C;springProfile name="prod">
    &#x3C;root level="WARN">
        &#x3C;appender-ref ref="ASYNC"/>
    &#x3C;/root>
&#x3C;/springProfile>

</configuration>

JSON Format (ELK Stack)

<appender name="JSON" class="ch.qos.logback.core.ConsoleAppender"> <encoder class="net.logstash.logback.encoder.LogstashEncoder"> <includeMdcKeyName>requestId</includeMdcKeyName> <includeMdcKeyName>userId</includeMdcKeyName> </encoder> </appender>

MDC Usage

import org.slf4j.MDC;

MDC.put("requestId", UUID.randomUUID().toString()); MDC.put("userId", user.getId()); try { // Business logic } finally { MDC.clear(); }

When NOT to Use This Skill

  • SLF4J API questions: Focus on API usage, not Logback implementation details

  • Log4j2 configuration: Different XML structure and features

  • Application code logging: Use SLF4J API, Logback is just the implementation

  • Non-Java projects: Use language-appropriate logging frameworks

  • Simple console output: System.out may be sufficient for basic scripts

Anti-Patterns

Anti-Pattern Why It's Bad Solution

Synchronous file appender in high-traffic Blocks application threads Use AsyncAppender wrapper

No rolling policy Logs fill disk space Use RollingFileAppender with size/time policies

Logging to console in production Performance overhead, lost logs Use file appenders, ship to centralized logging

DEBUG level in production Performance impact, disk usage Use INFO or WARN in production profiles

Not clearing MDC Memory leaks, wrong context in threads Always clear MDC in finally block

Hardcoded log paths Breaks across environments Use properties: ${LOG_PATH}

Quick Troubleshooting

Issue Cause Solution

Configuration not loaded Wrong file name/location Use logback-spring.xml in src/main/resources

Logs not rotating Missing rolling policy Add SizeAndTimeBasedRollingPolicy

Performance degradation Synchronous appenders Wrap with AsyncAppender

MDC values not appearing Pattern missing MDC placeholders Add %X{key} to pattern

Duplicate log entries Logger additivity enabled Set additivity="false" on logger

Profile-specific config ignored Using logback.xml instead Rename to logback-spring.xml for Spring profiles

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Coding

cron-scheduling

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

token-optimization

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

webrtc

No summary provided by upstream source.

Repository SourceNeeds Review
Coding

react-19

No summary provided by upstream source.

Repository SourceNeeds Review