LogBack Log4J successes, this is from the author who made Log4J. Log4J is currently out of date.
Here is an example of where the SLF4J / LogBack are simple:
Log4J (current)
Object entry = new SomeObject(); logger.debug("The new entry is "+entry+".");
Here are the tasks to be performed:
- Java calls the toString method on the variable record to get the string literal. Java initializes heap space to hold a String object.
- Java creates a new line based on the line above with "New Entry" and ".". Java initializes the storage space for an even more string literal.
- Java passes the new String object as an input parameter to Log4J. Log4J checks to see if the current logging level is DEBUG or higher. (assuming it is set to INFO in the logging.xml descriptor)
- Log4J does not print the string literal in the log because the logging level is set to INFO. (Therefore, all work on 1 - 2 was wasted).
SLF4J / LogBack (new)
Object entry = new SomeObject(); logger.debug("The new entry is {}.", entry);
Here are the tasks to be performed:
- Java passes the String object "New record {}." and recording the object as input to the SLF4J. SLF4J checks to see if the current logging level is DEBUG or higher. (assuming it is set to INFO in the logging.xml descriptor)
- Log4J does not print the string literal in the log because 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.
source share