Logging - Java

SLF4J

Cheatsheet

Multiple bindings were found on the class path (opens in a new tab)

Logback - Turn on debug flag

# System Property
-Dlogback.debug=true
# This will print out internal status messages of logback

MDC

  • Store contextual information on a per-thread basis, such as a transaction ID.

Modules

jul-to-slf4j

slf4j-jdk-platform-logging

Logback

Logback - Config

Logback - Appenders

  • immediateFlush

    By default, each log event is immediately flushed to the underlying output stream. This default approach is safer in the sense that logging events are not lost in case your application exits without properly closing appenders.

    Try using immediateFlush = true if logging events are lost in logs.

RollingFileAppender

  • RollingPolicy

    • How to roll over log files
  • TriggeringPolicy

    • When to roll over log files

Logback - Layout

PatternLayout

Logback - Integration

Spring Boot

  • Spring Boot by default uses programmatic configuration to improve startup time, with Spring config for customizations.

    Logback default config class: org.springframework.boot.logging.logback.DefaultLogbackConfiguration

Spring default config
org.springframework.boot.logging.logback