带有tomcat的JSF2日志 [英] JSF2 logs with tomcat

查看:85
本文介绍了带有tomcat的JSF2日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在tomcat6(6.0.28)上使用JSF2(2.1.2),Richfaces4(4.0.0.Final)的项目.为了管理我的EAR在Tomcat和WebSphere7之间的可移植性,我的tomcat库中有以下jar:el-api-2.2.jar,jsf-api-2.1.2.jar,jsf-impl-2.1.2.jar ,validation-api-1.0.0.GA.jar.

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.

我的问题是,我从未设法更改JSF或Richfaces的日志级别,并且除了初始化日志之外,我的控制台内看不到任何日志级别.即使我在服务器响应中遇到异常!

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 !

我尝试了几种方法:

1)在我的应用程序内部,我正在使用slf4j和log4j.因此,自然的方法是使用SLF4JBridgeHandler.install().我在其init()方法期间制作了一个小的Servlet来调用此方法,并添加了启动时加载"以确保在JSF Servlet之前加载了它(我不确定tomcat完全关心此启动时加载指令,因为我之前仍然从JSF init获取日志),例如:

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!

我还在log4j.xml中添加了一些配置:

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>

但是显示JSF页面时,我的控制台中没有看到任何日志... 我还尝试使用过滤器在执行JSF Servlet之前调用SLF4JBridgeHandler.install(),但是我从过滤器中仅获得了很多OK日志...

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)我试图按照教程此处准确(它会为每个JSF2记录器在tomcat日志文件夹中创建新文件).我尝试通过更改tomcat的conf文件夹内的logging.properties并在应用程序的src/resources/文件夹内添加新的logging.properties来进行尝试.但是没有运气...

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)我尝试通过添加以下命令将JSF记录器添加到tomcat内部的logging.properties中:

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

还没有运气...

4)我通过遵循

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...

有什么主意吗?

此致

弗洛里安

推荐答案

两个事实:

  • JSF使用 java.util.logging 由运行时类路径的根目录中的logging.properties文件配置的API.
  • 将使用当前正在运行的运行时环境(JRE)的logging.properties文件.
  • 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.

如果从像Eclipse这样的IDE内运行Tomcat,则将不使用Tomcat自己的logging.properties.将使用JDK/JRE/lib中的一个,其中"JDK"是JDK安装文件夹,例如jdk1.6.0_23.如果要显式指定logging.properties文件的位置,则需要设置VM参数:

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 

无论使用哪种日志文件,要启用Mojarra日志记录,您都需要打开有问题的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

进入

java.util.logging.ConsoleHandler.level = ALL

,以便将全局控制台级别设置为ALL而不是INFO.否则,根本不会记录低于INFO的级别.

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

第一个打开所有JSF API日志记录,第二个打开所有JSF impl(Mojarra)日志记录,第三个打开所有JSF Java EE日志记录.

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.

这篇关于带有tomcat的JSF2日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆