This article is participating in the Java Topic Month – Java Debug Notes event. See < activity link > for details.

** Question: Is Log4j abandoned by Slf4j? 台湾国

Log4j has some classloading issues (among others), and in my opinion, the trend is from Log4J to SLF4J. (Hibernate stops using the first one to support the latter)

1. Is it true

What are the main problems that SLF4J addresses with log4J?

3. Is SLF4J good on its own or is there a better “next next Log4J” industry standard?

Answer 1:

Slf4j is not a true logging look and feel. Slf4j does not support many of the functions of its implementor. In short, I’ve mentioned log4j below for comparison.

1. Slf4j cannot specify a configuration file of user choice, but will force the user to use the default value (log4j.properties or log4J.xml) in one of the many Java root directories (one for each Jar plus the JVM root and class or bin). If you have two JAR files, it is difficult to control which file to use safely.

2. Slf4j cannot support all Log4j levels, such as fatal. When you switch large code from Log4j to Slf4j, you need to make a lot of code changes (for example, deciding how to reorder levels).

3, you must select one of two key Jar files (log4j-over-slf4j. Jar or slf4J-log4j12.jar). If the classpath is selected, it will not work properly. If one is selected randomly, unexpected functionality is lost (for example, log4j-over-slf4j.jar does not support multiple log files of the same class; For example, one for event log and one for raw data log).