Search code examples
javaasynchronouslog4jslf4jlog4j2

Can i run my log asynchronously using log4j 1.x with log4j.properties file?


I am currently working on performance of "log4j 1.x" vs "logback" i.e. (slf4j).

I can append async to my logback, but i am not able to find any link which can async my log4j.

Async is only introduced in log4j 2.x? or is there any way to make my log4j 1.x work async.

Please assist me.

Thank you.


Solution

  • Asynchronous logging is one of Log4j 2's strong points. Instead of the AsyncAppender, use Async Loggers: the performance is much better.

    The Log4j 2 performance page compares Log4j-1.x, Logback and Log4j 2. Take a look and then decide what logging framework to use.

    By the way, Log4j 2 has an adapter called log4j-1.2-api-2.6.jar which lets your application use the old log4j-1.2 API, but uses the new log4j 2 implementation.

    (Log4j-1.x also has an AsyncAppender. Just like the Log4j 2 AsyncAppender and the Logback AsyncAppender, it uses a BlockingQueue. Log4j 2's Async Loggers use a non-blocking data structure which is much faster.)