Difference between AsyncLogger and AsyncAppender in Log4j2

Not taking anything away from the accepted answer, but take a look at https://logging.apache.org/log4j/2.x/manual/async.html. The page includes performances measurements taken by the log4j2 team, where async loggers outperform async appenders by quite some margin.


True, they achieve pretty much the same purpose, so I can understand your question: "why have both options"?

For background, the AsyncAppender has been in Log4j2 from the beginning, where Async Loggers were added in March last year (2014). That's how the current situation came to be.

The log4j team is not seriously considering removing the AsyncAppender at the moment. One thing to keep in mind is that Async Loggers have an external dependency (the LMAX disruptor jar) where the AsyncAppender works with just the log4j2-api and log4j2-core jars.

To answer your last question, it is possible to combine AsyncAppender with Async Loggers, but you will not gain anything. This has not been tested. I haven't checked but it is possible that there is a problem with location information getting lost when handing over the log event from the Async Logger thread to the AsyncAppender thread. I would not recommend doing this.

UPDATE (2014/6/23): I did some testing and there were a few issues with combining AsyncAppender with AsyncLoggers. These are fixed in RC2. I still don't recommend doing this, as it just adds another intermediate step that uses CPU/memory without contributing anything.

UPDATE (2016/7/20): Another difference: since version 2.6, Log4j 2 can be garbage-free with Async Loggers, but not with AsyncAppender.


In answer to your second question in the comments below: AsyncAppender has its own queue and thread, where AsyncLoggers use the LMAX Disruptor ringbuffer for a queue and uses an Executor thread.