When comparing log4j2 vs Logback, the Slant community recommends log4j2 for most people. In the question“What is the best Java logging framework?” log4j2 is ranked 1st while Logback is ranked 2nd. The most important reason people chose log4j2 is:
log4j2 is SLF4J-compliant, so you can switch to using other logging libraries that implements the SLF4J API.
Ranked in these QuestionsQuestion Ranking
Pros
Pro Can switch to using other SLF4J-compliant logging libraries
log4j2 is SLF4J-compliant, so you can switch to using other logging libraries that implements the SLF4J API.
Pro Great performance
log4j2 uses asynchronous loggers which provide higher log throughput, low latency, and faster overall performance.
Pro Allows you to load the config from a file on the file system rather than classpath
Pro Can be used for virtually all circumstances
Since it has a very generic architecture. logback can be used for any scenario that may arise.
Pro Archived log files can be automatically compressed
Logback can automatically compress log archives. It does this asynchronously, so the main application isn't blocked when compression is running.
Pro Flexible and powerful filtering
Logback's filtering capabilities are powerful and more flexible than other logging solutions.