10

I've got a web-app deployed to a Tomcat 7 server. My application uses log4j and a file appender. However, not all logging messages are getting written to the file.

On my classpath, I have:

log4j-1.2.14.jar
slf4j-api-1.6.1.jar
slf4j-log4j12-1.6.1.jar

My log4j.properties file is working fine on my local machine and is deploy properly.

I see application generated error messages being written to catalina.out that are not getting written to my log4j log. The log messages in catalina.out look to be coming from some other logging framework because the output pattern is in a different format than my log4j pattern. The logging that I'm seeing in the catalina.log is like:

Nov 4, 2011 11:05:31 AM org.apache.myfaces.shared_impl.util.StateUtils reconstruct
SEVERE

And my log4j pattern is like:

2011-11-03 16:42:09,336 ["http-bio-8080"-exec-13] ERROR

Some logging appears in my log4j file log, but not all of it. From what I've read, slf4j just needs those jars for it to funnel log output. Any ideas?

Avi
  • 21,182
  • 26
  • 82
  • 121
user935265
  • 254
  • 1
  • 2
  • 10
  • You might try using the slf4j jar named "log4j-over-slf4j-1.6.1.jar" instead of the log4j jar named "log4j-1.2.14.jar" – DwB Nov 04 '11 at 16:34
  • log4j-over-slf4j.jar is a log4j replacement. The asker does not want to replace log4j. DwB, I suggest that you delete your comment as it is misleading. – Ceki Nov 04 '11 at 21:03

3 Answers3

13

It looks like the StateUtils class is using java.util.logging (jul). It stands to reason that other myfaces classes also use jul. Thus, you would probably want to funnel jul logs through SLF4J. Have a look at bridging legacy APIs, in particular the jul-to-slf4j bridge.

Please see SLF4JBridgeHandler javadocs for usage instructions when installing jul-to-slf4j.

Ceki
  • 26,753
  • 7
  • 62
  • 71
  • I tried including both jul-to-slf4j & jcl-over-slf4j dependencies one at a time & another time both together but nothing happened, Still can't see logs by myfaces. The logs from rest of my application are successfully routed to logback via SL4J & written both to file & to netbeans console but cannot see myfaces logs. Do you have any suggestions ? – Rajat Gupta Aug 23 '12 at 15:35
  • 1
    Please see SLF4JBridgeHandler javadocs for usage instructions when installing jul-to-slf4j. – Ceki Aug 23 '12 at 16:18
  • Thanks as per your suggestion I tried after installing SLF4JBridgeHandler properly & it worked! However using a more performant approach using `LevelChangePropagator` didn't worked out. However that's a different issue. Thanks anyways. In 1st case,I got 2 messages for each log (ie, like this:) `INFO j.e.s.s.c.s.e.server.logging -> INFO o.a.m.webapp.WebConfigParamsLogger -> No context init parameter ... found.` `INFO o.a.m.webapp.WebConfigParamsLogger -> No context init parameter ... found` – Rajat Gupta Aug 23 '12 at 18:32
  • Also could you explain why didn't Myfaces allowed the flexibility to plug in your desired logging implementation instead of using JUL/ Commons logging ?! – Rajat Gupta Aug 23 '12 at 18:36
  • "why" questions can only be answered by the Myfaces designers themselves. Note that commons-logging is quite old, I would rather ask framework designers to actually use SLF4J. – Gimby Jan 08 '13 at 09:48
2

Configure your tomcat server according to the steps described at http://adfinmunich.blogspot.de/2012/03/how-to-configure-tomcat-to-use-slf4j.html. This blog entry describes how to replace java.util.logging by slf4j (using log4j behind the facade).

Florian Sager
  • 660
  • 8
  • 14
2

try including the jcl-over-slf4j as a dependency. myfaces is probably using commons-logging.

check the slf4j docs: http://www.slf4j.org/legacy.html#jcl-over-slf4j

Stefan De Boey
  • 2,344
  • 16
  • 14