9
votes

Can anyone tell me the difference between slf4j-log4j and log4j-over-slf4j? Which is more standard to use in a Java web application? I currently have both on the classpath and that is causing a runtime exception as the web server is trying to prevent a StackOverFlowException from happening.

Exception:

java.lang.IllegalStateException:
Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class path

2
Removing both would be a nice idea.Roman C
I'd suggest that you examine the contents of both and figure out how they are different.Hot Licks
It depends, on web framework, and logging implementation. Also it depends on server, but it is a different question.Roman C
possible duplicate of difference between slf4j and log4jRoman C
seems like using slf4j and logback is very popularc12

2 Answers

23
votes

slf4j-log4j is using log4j as an implementation of slf4j.

log4j-over-slf4j causes calls to the log4j API to be 'routed' to slf4j.

You cannot use both of these JAR's at the same time.

Both are valid libraries to use and are equally 'standard', it depends on the project.

In general, if your project is using log4j already and you don't have the ability to update all of your log4j Loggers to slf4j Loggers; log4j-over-slf4j is a quick fix to be able to start using slf4j immediately.

However, if your project is new or does not have an existing logging mechanism and you choose to use slf4j, slf4j-log4j would be the way to go as it is just specifying slf4j should be bound to log4j.

That being said, I agree with c12's comment. Stop using log4j and instead use slf4j and logback.

2
votes

in my project , org.slf4j.impl.Log4jLoggerFactory is in

activemq-all-5.7.0.jar

not in slf4j-log4j12.jar

the exception message mislead me