Is Logback mature enough to replace log4j?
java, log4j, logback, slf4j
Solution
LogBack successes Log4J, it is from the author who made Log4J. Log4J is currently deprecated.
Here is an example of where SLF4J / LogBack primes:
Log4J (Current)
Object entry = new SomeObject();
logger.debug("The new entry is "+entry+".");
Here are the tasks performed:
- Java calls on toString method on the variable entry to get the String literal representation. Java initializes space in heap to hold the String object.
- Java creates a new String based on the above String, with “The new entry is “ and “.”. Java initializes space to hold the yet newer String literal.
- Java passes on the newly constructed String object as input parameter to Log4J. Log4J checks if the current logging level is DEBUG and above. (assuming it was set to INFO in logging.xml descriptor)
- Log4J does not print out the String literal into the log, since the logging level is set to INFO. (Therefore all the work on 1 – 2 was wasted)
SLF4J / LogBack (New)
Object entry = new SomeObject();
logger.debug("The new entry is {}.", entry);
Here are the tasks performed:
- Java passes on the String object “The new entry is {}.” and object entry as input parameters to SLF4J. SLF4J checks if the current logging level is DEBUG and above. (assuming it was set to INFO in logging.xml descriptor)
- Log4J does not print out the String literal into the log, since the logging level is set to INFO.
http://www.slf4j.org/faq.html#logging_performance
Ability to replace tomcat-default jul logging with logback/log4j loggin?
Yes, use with SLF4J.
Problem
I have read similar questions on SO like this and this. But they are about four years old! Also I have read this logback page, which has some really good info on why to choose Logback over log4j. I am looking to implement a logging framework for a project with the following technology stack - - Spring - Hibernate - Maven - Tomcat - Rest I have already decided to use slf4j as the facade, so this question is on whether to use slf4j + log4j or slf4j + logback (I know that logback natively uses slf4j). What I am looking for is following - - Has anyone had an experience with Logback that would prove it to be not as mature or efficient as log4j? - How does it fair as compared to log4j in a multi-threaded environment? - Ability to replace tomcat-default jul logging with logback/log4j logging - Ability to consolidate logging configuration into a common file for a maven multi-module project - Logback claims it's 10 times faster than log4j, has anyone validated that claim? (as part of my research I do plan to run some tests to measure performance and will post back my results) EDIT: I've read at many places (one of the answer below states this as well) that log4j is dead/deprecated. Contrary to that, log4j just released an alpha version of its 2.0 release. So I do not buy that argument.