Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

slf4j

log4j

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

like image 400
c12 Avatar asked Aug 19 '13 17:08

c12


2 Answers

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.

like image 147
FGreg Avatar answered Oct 06 '22 01:10

FGreg


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

like image 33
user2665136 Avatar answered Oct 06 '22 01:10

user2665136