• Five of log4j's six logging levels are used (ERROR, WARN, INFO, DEBUG, TRACE). FATAL has been dropped on the basis that inside the logging framework is not the place to decide when an application should terminate and therefore there is no difference between ERROR and FATAL from the logger's point of view. In addition, SLF4J markers offer a more general method for tagging log statements. For example, any log statement of level ERROR can be tagged with the "FATAL" marker. • Logger instances are created via the LoggerFactory, which is very similar in log4j. For example, private static final Logger LOG = LoggerFactory.getLogger(Wombat.class); • In
Logger, the logging methods are
overloaded with forms that accept one, two or more values. Occurrences of the simple pattern {} in the log message are replaced in turn with the values. This is simple to use yet provides a performance benefit when the values have expensive toString() methods. When logging is disabled at the given level, the logging framework does not need to evaluate the string representation of the values, or construct a log message string that is never actually logged. In the following example, string concatenation and toString() method for the values count or userAccountList are performed only when DEBUG is enabled. LOG.debug("There are now " + count + " user accounts: " + userAccountList); // slower LOG.debug("There are now {} user accounts: {}", count, userAccountList); // faster • Similar methods exist in
Logger for isDebugEnabled() etc. to allow more complex logging calls to be wrapped so that they are disabled when the corresponding level is disabled, avoiding unnecessary processing. • Unlike
log4j, SLF4J offers logging methods that accept markers. These are special objects that enrich the log messages. At present time,
logback is the only framework which makes use of markers. ==Similarities and differences with log4j 2.x==