Configuring Logback for Asynchronous Logging in Spring Boot and Performance Comparison
This article explains how to configure Logback in a Spring Boot application to separate logs by level, implement asynchronous logging with AsyncAppender, and compare performance using JMeter, demonstrating a tenfold throughput increase while providing detailed XML configuration examples and underlying implementation details.
The article introduces a step‑by‑step guide for Spring Boot developers to configure Logback so that logs are written to different files based on their LEVEL , and to enable asynchronous logging to reduce disk I/O overhead.
What you will learn
Log output to files categorized by level.
How asynchronous logging improves performance by avoiding blocking I/O.
The underlying mechanism of asynchronous logging in Logback.
Logback configuration (logback‑spring.xml)
[%d{yyyy-MM-dd' HH:mm:ss.SSS}] [%C] [%t] [%L] [%-5p] %m%n
ERROR
DENY
ACCEPT
[%d{yyyy-MM-dd' HH:mm:ss.SSS}] [%C] [%t] [%L] [%-5p] %m%n
${LOG_INFO_HOME}//%d.log
30
ERROR
[%d{yyyy-MM-dd' HH:mm:ss.SSS}] [%C] [%t] [%L] [%-5p] %m%n
${LOG_ERROR_HOME}//%d.log
30Advanced feature: Asynchronous output
0
256
0
256Performance test
Using Apache JMeter with 100 concurrent threads, the synchronous configuration achieved a throughput of 44.2 requests per second, while the asynchronous configuration reached 497.5 requests per second – more than a ten‑fold increase.
How asynchronous logging works
When Logger.info(...) is called, Logback’s AsyncAppenderBase places the event into an ArrayBlockingQueue . A dedicated worker thread takes events from the queue and invokes AppenderAttachableImpl.appendLoopOnAppenders(e) , which writes the log to the underlying file appender. The key methods involved are encode and write .
protected void append(E eventObject) {
if (!this.isQueueBelowDiscardingThreshold() || !this.isDiscardable(eventObject)) {
this.preprocess(eventObject);
this.put(eventObject);
}
}
E e = parent.blockingQueue.take();
aai.appendLoopOnAppenders(e);The article concludes with a summary of the configuration steps, a reminder to use the async appender for high‑throughput services, and links to additional resources and interview questions.
Top Architect
Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.