]> juplo.de Git - website/blob
2584b6b950bcd7f8780343f64b52b49b7b908d46
[website] /
1 ---
2 _edit_last: "2"
3 author: kai
4 categories:
5   - java
6   - jetty
7 date: "2014-06-03T09:55:28+00:00"
8 guid: http://juplo.de/?p=291
9 parent_post_id: null
10 post_id: "291"
11 title: Changes in log4j.properties are ignored, when running sl4fj under Tomcat
12 url: /changes-in-log4j-properties-are-ignored-when-running-sl4fj-under-tomcat/
13
14 ---
15 Lately, I run into this very subtle bug:
16 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`.
17 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.
18 _But - very strange - my configuration-file was not ignored completely._
19 The appender-configuration and the log-level from the root-logger where picked up from my configuration-file.
20 **Only all special logger-configuration were ignored**.
21
22 ## Erroneous logging-configuration
23
24 Here is my configuration, as it was when I run into the problem:
25
26 - Logging was done with [slf4j](http://www.slf4j.org "Learn more about slf4j")
27 - Logs were written by [log4j](http://logging.apache.org/log4j/2.x/ "Learn more about log4j") with the help of **slf4j-log4j12**
28 - 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.
29    I used: **jcl-over-slf4j** and **log4j-over-slf4j**.
30
31 ## Do not use sl4fj-log4j and log4j-over-slf4j together!
32
33 As said before:
34 _All worked as expected while developing under Jetty and in production under Tomcat, only special logger-confiugrations where ignored._
35
36 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**.
37 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
39 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").
40 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!
41 So, I hope I can save you some time by dragging your attention to this.
42
43 ## The solution
44
45 Only the cause is hard to find.
46 The solution is very simple:
47 **Just switch from log4j to [logback](http://logback.qos.ch/index.html "Learn more about logback")**.
48
49 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").