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
-
By default,
additivity="true"
which sends logging output to any appender attached higher in the hierarchy.Try setting
additivity="false"
if duplicate logging output happens. -
Logback - Chapter 3 Configuration - Overriding the default cumulative behaviour (opens in a new tab)
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
-
Colored output
Jansi
library is required forANSI
color code interpretation on Windows.POSIX
systems supportANSI
color code interpretation natively.
-
Logback - Chapter 6 Layouts - PatternLayout (opens in a new tab)
Reference for conversion patterns
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