This gist demonstrates configuring asynchronous logging with Logback in a Spring Boot application. This approach provides improved performance, reduced latency, scalability, and fault tolerance.
By leveraging existing Spring logging configuration properties, we can customize the logging behavior according to your application's requirements seamlessly based on the envirement variables declared in defaults.xml. See Custom log configuration
Important
Contrary to the default configuration, file logging (ASYNC_FILE) is enabled even if logging.file.name
or logging.file.path
are not used.
Logging configuration is defined in logback-spring.xml
within src/main/resources
. The AsyncAppender
wraps both console and file appenders to enable asynchronous logging, enhancing performance and fault tolerance.
Here's a list of AsyncAppender parameters and their default values:
-
queueSize: Maximum capacity of the blocking queue. Default value is 256.
-
discardingThreshold: By default, drops events of TRACE, DEBUG, INFO when the queue has 20% capacity remaining; set to 0 to keep all events.
-
includeCallerData: Exclude expensive caller data for better performance. Default value is false.
-
maxFlushTime: Maximum time in milliseconds the AsyncAppender waits for the queue to flush during shutdown. Default value is not set.
-
neverBlock: Appender blocks on full queue (default) or drops message if true. Default value is false.
These parameters can be configured within the AsyncAppender
element in the Logback configuration file to customize the behavior of asynchronous logging.