Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logback Logging - Synchronous or Asynchronous

Is the default file appended of Logback:

ch.qos.logback.core.FileAppender

synchronous or asynchronous? It seems to be synchronous as the logs are being shown as part of same thread.

like image 532
Sandeep Jindal Avatar asked May 04 '15 23:05

Sandeep Jindal


People also ask

Is Log4j synchronous or asynchronous?

Asynchronous logging can improve your application's performance by executing the I/O operations in a separate thread. Log4j 2 makes a number of improvements in this area. Asynchronous Loggers are a new addition to Log4j 2. Their aim is to return from the call to Logger.

What is synchronous and asynchronous logging?

In synchronous mode, the logger writes entries directly to the destination. In asynchronous mode, the logger writes entries to a queue, then later writes the entries from the queue to the destination.

What is Logback logging?

Logback is a logging framework for Java applications, created as a successor to the popular log4j project. In fact, both of these frameworks were created by the same developer.

Which is better Logback or Log4j2?

Log4j, Logback, and Log4j2 are good logging frameworks that are broadly used. So which one should you use? I recommend using Log4j2 because it's the fastest and most advanced of the three frameworks. Logback is still a good option, if performance is not your highest priority.


1 Answers

Most appenders are synchronous, for example, RollingFileAppender. To enable async logging, you must wrap an appender with AsyncAppender to create an async appender based on the sync one, and it could be done easily in XML like below.

<appender name="ASYNC-VERSION-APPENDER" class="ch.qos.logback.classic.AsyncAppender">
    <appender-ref ref="DEFAULT-APPENDER"/>
</appender>
<logger name="ASYNC-LOGGER" level="INFO" additivity="false">
    <appender-ref ref="ASYNC-VERSION-APPENDER"/>
</logger>
like image 87
ProtossShuttle Avatar answered Sep 26 '22 02:09

ProtossShuttle