Is Logback mature enough to replace log4j?

I read similar questions about SO like this and this . But they are about four years old!

I also read this page , where there is some really good information on why to choose Logback over log4j.

I am looking to implement a journal framework for a project with the following technology stack -

  • Spring
  • Hibernate
  • Maven
  • Tomcat
  • Relaxation

I already decided to use slf4j as a facade, so this question is whether to use slf4j + log4j or slf4j + logback (I know that logback initially uses slf4j).

I am looking for the following -

  • Does anyone have any experience with Logback that proves that it is not as mature or efficient as log4j?
  • How is this true compared to log4j in a multi-threaded environment?
  • Ability to replace tomcat-default jul logging with logback / log4j protocol
  • Ability to consolidate logging configuration into a common file for maven multi-module project
  • The error statement is 10 times faster than log4j, has anyone confirmed this requirement? (As part of my research, I plan to run some tests to measure performance and publish my results).

EDIT . I read in many places (one of the answers below also states that log4j is dead / outdated. Contrary to this, log4j just released an alpha version of its version 2.0. Therefore, I am not buying this argument.

+6
source share
1 answer

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.

+10
source

Source: https://habr.com/ru/post/920670/


All Articles