Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Log4j being abandoned in favor of Slf4j? [closed]

Tags:

java

slf4j

log4j

It seems that log4j has some class loading issues (among others) and it seems to me the trend is to move out of log4j toward slf4j. (Hibernate stopped using the first in favor of the latter)

  1. Is it true?
  2. What are the main issues in log4j that slf4j solves?
  3. Is slf4j the final word or is there even a better "the next next log4j" industry standard?

Update:

  • So this answer by delfuego confuses me, can you accept / object it?:

You appear to have stumbled upon the major problem with log4j (and the Apache Commons Logging library), namely that they have a ridiculously hard time discovering and interacting with the right classloaders as they're being used. There's a very dense explanation, complete with examples, here; the take-home message is that one of the primary driving forces for the new logging framework SLF4J was to eliminate these issues entirely. You might want to swap it in and see if your life is made any easier.

  • More classloading issues by log4j: http://articles.qos.ch/classloader.html
like image 509
ruchirhhi Avatar asked Jan 14 '10 12:01

ruchirhhi


People also ask

Is log4j over SLF4J affected?

The SLF4J API is just an API which lets message data go through. As such, using log4j 2. x, even via SLF4J does not mitigate the vulnerability.

Can SLF4J replace log4j?

Conclusion. So essentially, SLF4J does not replace Log4j, Both work together. SLF4j removes the tight coupling between the application and logging frameworks. It makes it easy to replace with any other logging framework in the future with a more capable library.

Can I use log4j without SLF4J?

So essentially, SLF4J does not replace log4j; they both work together. It removes the dependency on log4j from your application and makes it easy to replace it in the future with the more capable library.

Is SLF4J using log4j?

SLF4J supports popular logging frameworks, namely log4j, java. util. logging, Simple logging and NOP.


1 Answers

Slf4j is indeed just a logging facade. However, Log4j is intended to be succeeded by Logback, from the very same authors.

Update: if you'd like to know about another benefit of Slf4j, it's the fact that following (ugly) constructs aren't needed anymore to avoid the toString() unnecessarily been called:

if (logger.isDebugEnabled()) {     logger.debug("Message: " + bigObject + ", " + anotherBigObject); } 

You can instead make use of parameterized messages:

logger.debug("Message: {}, {}", bigObject, anotherBigObject); 

Also see What is the fastest way of (not) logging?

like image 171
BalusC Avatar answered Sep 19 '22 15:09

BalusC