Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
717 views
in Technique[技术] by (71.8m points)

jsf - JSF2 logs with tomcat

I'm having a project using JSF2 (2.1.2), Richfaces4 (4.0.0.Final) on tomcat6 (6.0.28). In order to manage portability between Tomcat and WebSphere7 for my EARs, I have the following jars inside my tomcat lib: el-api-2.2.jar, jsf-api-2.1.2.jar, jsf-impl-2.1.2.jar, validation-api-1.0.0.GA.jar.

My problem is that I never managed to change the log levels of JSF or Richfaces and except from the initialization ones, I don't see any inside my console. Even when I get exceptions in my server response !

I tried several ways:

1) Inside my applications, I'm using slf4j and log4j. So the natural way would be to use SLF4JBridgeHandler.install(). I made a small servlet to call this method during its init() method and added a 'load-on-startup' to be sure it's loaded before JSF Servlet (I'm not sure tomcat cares at all about this load-on-startup directive because I still get logs from JSF init before), e.g.:

INFO: JSF1027 : [null] Les objets ELResolvers de JSF n’ont pas été enregistrés avec le conteneur JSP.
09-09-2011 16:50:58:591 [Thread-2] 937  DEBUG com.jsf.test.SLF4JBridgeHandlerInstallerServlet - SLF4JBridgeHandler.install() OK!

I also added some configuration in my log4j.xml:

<logger name="javax.faces"><level value="debug"/></logger>  
<logger name="com.sun.faces"><level value="debug"/></logger>
<logger name="javax.enterprise.resource.webcontainer.jsf"><level value="debug"/></logger>

But I don't see any logs in my console when displaying a JSF page... I also tried using a filter to call SLF4JBridgeHandler.install() before the execution of the JSF Servlet, but I only get a lot of OK logs from my filter...

2) I tried to follow the tutorial here exactly (it creates new files in tomcat log folder for each logger of JSF2). I tried by changing the logging.properties inside the conf folder of tomcat and by adding a new logging.properties inside my src/resources/ folder in my application. But no luck...

3) I tried to add the JSF loggers to the the logging.properties inside my tomcat by adding this:

javax.enterprise.resource.webcontainer.jsf.managedbean.level=FINEST
javax.enterprise.resource.webcontainer.jsf.managedbean.handlers = java.util.logging.ConsoleHandler
javax.enterprise.resource.webcontainer.jsf.config.level=FINEST
javax.enterprise.resource.webcontainer.jsf.config.handlers = java.util.logging.ConsoleHandler
javax.enterprise.resource.webcontainer.jsf.facelets.level=FINEST
javax.enterprise.resource.webcontainer.jsf.facelets.handlers = java.util.logging.ConsoleHandler
javax.enterprise.resource.webcontainer.jsf.resource.level=FINEST
javax.enterprise.resource.webcontainer.jsf.resource.handlers = java.util.logging.ConsoleHandler
javax.enterprise.resource.webcontainer.jsf.lifecycle.level=FINEST
javax.enterprise.resource.webcontainer.jsf.lifecycle.handlers = java.util.logging.ConsoleHandler

No luck yet...

4) I tried to use log4j inside tomcat instead of juli by following this documentation. It seems to work well, but changing the resulting log4j.properties to put the JSF loggers in DEBUG didn't work...

Any idea ?

Regards,

Florian

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Two facts:

  • JSF uses java.util.logging API which is to be configured by a logging.properties file in the root of the runtime classpath.
  • The logging.properties file of the currently(!) running runtime environment (JRE) will be used.

If you're running Tomcat from inside an IDE like Eclipse, then Tomcat's own logging.properties won't be used. The one in JDK/JRE/lib will be used where "JDK" is the JDK install folder such as jdk1.6.0_23. If you'd like to explicitly specify the location of the logging.properties file, then you would need to set a VM argument:

-Djava.util.logging.config.file=/path/to/tomcat/logging.properties 

Regardless of the logging file used, in order to enable Mojarra logging, you need to open the logging.properties template file in question, scroll to the bottom and edit the following line near the bottom

java.util.logging.ConsoleHandler.level = INFO

into

java.util.logging.ConsoleHandler.level = ALL

so that the global console level is set to ALL instead of INFO. Otherwise lower levels than INFO just won't be logged at all.

Finally add the following two lines to the very bottom of the file

javax.faces.level = ALL
com.sun.faces.level = ALL
javax.enterprise.resource.webcontainer.jsf.level = ALL

The first turns on all JSF API logging, the second turns on all JSF impl (Mojarra) logging, and the third turns on all JSF Java EE logging.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...