6 date: "2014-06-03T09:55:28+00:00"
7 guid: http://juplo.de/?p=291
10 title: Changes in log4j.properties are ignored, when running sl4fj under Tomcat
11 url: /changes-in-log4j-properties-are-ignored-when-running-sl4fj-under-tomcat/
14 Lately, I run into this very subtle bug:
15 my logs were all visible, like intended and configured in `log4j.properties` (or `log4j.xml`), when I fired up my web-application in development-mode under [Jetty](http://www.eclipse.org/jetty/ "Lern more about Jetty") with `mvn jetty:run`.
16 But if I installed the application on the production-server, which uses a [Tomcat 7](http://tomcat.apache.org/ "Lern more about Tomcat") servlet-container, no special logger-configuration where picked up from my configuration-file.
17 _But - very strange - my configuration-file was not ignored completely._
18 The appender-configuration and the log-level from the root-logger where picked up from my configuration-file.
19 **Only all special logger-configuration were ignored**.
21 ## Erroneous logging-configuration
23 Here is my configuration, as it was when I run into the problem:
25 - Logging was done with [slf4j](http://www.slf4j.org "Learn more about slf4j")
26 - Logs were written by [log4j](http://logging.apache.org/log4j/2.x/ "Learn more about log4j") with the help of **slf4j-log4j12**
27 - Because I was using some legacy libraries, that were using other logging-frameworks, I had to include some [bridges](http://www.slf4j.org/legacy.html "Lern more about slf4j-bridges") to be able to include the log-messages, that were logged through this frameworks in my log-files.
28 I used: **jcl-over-slf4j** and **log4j-over-slf4j**.
30 ## Do not use sl4fj-log4j and log4j-over-slf4j together!
33 _All worked as expected while developing under Jetty and in production under Tomcat, only special logger-confiugrations where ignored._
35 Because of that, it took me quiet a while and a lot of reading, to figure out, that **this was not a configuration-issue, but a clash of libraries**.
36 The cause of this strange behaviour were the fact, that **one must not use the log4j-binding _slf4j-log4j12_ and the log4j-bridge _log4j-over-slf4j_ together**.
38 This fact is quiet logically, because it _should_ push all your logging-statements into an endless loop, where they are handed back and forth between sl4fj and log4j as stated in the sl4fj-documentation [here](http://www.slf4j.org/legacy.html#log4j-over-slf4j "Here you can read the warning in the documentation").
39 But if you see all your log-messages in development and in production only the configuration behaves strangley, this mistake is realy hard to figure out!
40 So, I hope I can save you some time by dragging your attention to this.
44 Only the cause is hard to find.
45 The solution is very simple:
46 **Just switch from log4j to [logback](http://logback.qos.ch/index.html "Learn more about logback")**.
48 There are some more good reasons, why you should do this anyway, over which you can [learn more here](http://logback.qos.ch/reasonsToSwitch.html "Learn why you should switch from log4j to logback anyway").