使用 tomcat 的 JSF2 日志 [英] JSF2 logs with tomcat

查看:27
本文介绍了使用 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().我制作了一个小 servlet 来在它的 init() 方法期间调用这个方法,并添加了一个load-on-startup"以确保它在 JSF Servlet 之前加载(我不确定 tomcat 是否关心这个 load-on-startup指令,因为我之前仍然从 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) 我尝试在 tomcat 中使用 log4j 而不是 juli 遵循 本文档.它似乎运行良好,但更改生成的 log4j.properties 以将 JSF 记录器置于 DEBUG 中不起作用...

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

以便将 global 控制台级别设置为 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天全站免登陆