日期:2014-05-16  浏览次数:20367 次

Tomcat中如何打开Sun JSF RI 1.2中的日志
为了更加清楚的了解JSF请求在每一个生命周期中的执行情况,我们有时候需要打开JSF本身的log,查看log 输出情况。本文以Sun的JSF RI 1.2为例,说明如何打开log。

通过源码可以看出, Sun JSF RI 1.2使用的日志是Java.util.Logging,这个与Apache的Log4J略有不同,是JVM级别的log,但是在Tomcat 6中对这个Log进行了扩展,详细的扩展信息可以参考http://tomcat.apache.org/tomcat-6.0-doc/logging.html,这里我们仅仅介绍如何使用。

   打开方法很简单,在我们单独的Web应用的src目录下,添加一个logging.properties文件,文件内容如下:
Java代码

   1. handlers = org.apache.juli.FileHandler, java.util.logging.ConsoleHandler 
   2.  
   3. ############################################################ 
   4. # Handler specific properties. 
   5. # Describes specific configuration info for Handlers. 
   6. ############################################################ 
   7.  
   8. org.apache.juli.FileHandler.level = FINE 
   9. org.apache.juli.FileHandler.directory = ${catalina.base}/logs 
  10. org.apache.juli.FileHandler.prefix = sample. 
  11.  
  12. java.util.logging.ConsoleHandler.level = FINE 
  13. java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter 
  14.  
  15. javax.enterprise.resource.webcontainer.jsf.level=FINE 
  16. javax.enterprise.resource.webcontainer.jsf.lifecycle.level=FINE 

handlers = org.apache.juli.FileHandler, java.util.logging.ConsoleHandler

############################################################
# Handler specific properties.
# Describes specific configuration info for Handlers.
############################################################

org.apache.juli.FileHandler.level = FINE
org.apache.juli.FileHandler.directory = ${catalina.base}/logs
org.apache.juli.FileHandler.prefix = sample.

java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter

javax.enterprise.resource.webcontainer.jsf.level=FINE
javax.enterprise.resource.webcontainer.jsf.lifecycle.level=FINE



这样就会打开Sun中所有的JSF log日志,记录在Tomcat/logs/sample.xxx.log文件中。如果只需要生命周期的,把倒数第二行去掉即可。

Sun的这些日志信息记录在Util类中,相关信息如下:
Java代码

   1. public static final String FACES_LOGGER = "javax.enterprise.resource.webcontainer.jsf"; 
   2.  
   3. public static final String FACES_LOG_STRINGS =  
   4.         "com.sun.faces.LogStrings";         
   5.  
   6. // Log instance for this class 
   7. private static final Logger LOGGER = getLogger(FACES_LOGGER); 
   8.  
   9. // README - make sure to add the message identifier constant 
  10. // (ex: Util.CONVERSION_ERROR_MESSAGE_ID) and the number of substitution 
  11. // parameters to test/com/sun/faces/util/TestUtil_messages (see comment there). 
  12.  
  13. // Loggers 
  14. public static final String RENDERKIT_LOGGER = ".renderkit"; 
  15. public static final String TAGLIB_LOGGER = ".taglib"; 
  16. public static final String APPLICATION_LOGGER = ".application"; 
  17. public static final String CONTEXT_LOGGER = ".context"; 
  18. public static final String CONFIG_LOGGER = ".config"; 
  19. public static final String LIFECYCLE_LOGGER = ".lifecycle"; 
  20. public static final String TIMING_LOGGER = ".timing"; 



From: http