2013-03-26 82 views
1

我们正在准备将我们的JSF 2(MyFaces with Facelets页面)应用程序移至生产环境。目前,我们的控制台日志(在WebSphere V8 SystemOut.log中)与大量的这类消息的填充:如何抑制MyFaces控制台的html警告?

[3/26/13 16:42:33:744 CDT] 00000031 HtmlImageRend W Component UIGraphic Form:errorIconSave has no attribute alt or attribute resolves to null. Path to component {Component-Path : [Class: javax.faces.component.UIViewRoot,ViewId: /view/groupagreement/products/volumebased/VolumeBasedProducts.xhtml][Class: javax.faces.component.html.HtmlBody,Id: commonLayoutId][Class: javax.faces.component.html.HtmlPanelGrid,Id: j_id1364021679_785179b][Class: javax.faces.component.html.HtmlForm,Id: Form][Class: javax.faces.component.html.HtmlBody,Id: j_id363369746_1d362e8b][Class: javax.faces.component.html.HtmlPanelGrid,Id: j_id363369746_1d362e61][Class: org.richfaces.component.UIRegion,Id: j_id363369746_1d362e4a][Class: org.richfaces.component.UIPopupPanel,Id: confirmationPopUpForWayFinder][Class: javax.faces.component.html.HtmlPanelGrid,Id: j_id363369746_1d362ffd][Class: javax.faces.component.html.HtmlPanelGrid,Id: j_id363369746_1d362fbc][Class: javax.faces.component.html.HtmlPanelGrid,Id: j_id363369746_1d362f9a][Class: javax.faces.component.html.HtmlPanelGrid,Id: j_id363369746_1d362f70][Class: javax.faces.component.html.HtmlGraphicImage,Id: errorIconSave]} 
[3/26/13 16:42:33:746 CDT] 00000031 HtmlResponseW W HTML nesting warning on closing div: element td rendered by component : {Component-Path : [Class: javax.faces.component.UIViewRoot,ViewId: /view/groupagreement/products/volumebased/VolumeBasedProducts.xhtml][Class: javax.faces.component.html.HtmlBody,Id: commonLayoutId][Class: javax.faces.component.html.HtmlPanelGrid,Id: j_id1364021679_785179b]} not explicitly closed 

我们觉得这个过度砍伐可能损害性能。虽然我们知道我们应该将应用程序编码为html规范,但它是由离岸供应商提供的,我们对代码的质量没有太多的控制。此时我们可能没有时间修复所有的xhtml文件(将alt属性添加到图像等)。

有没有什么办法可以禁用这个日志记录?例如一个web.xml上下文参数?我在MyFaces文档中找不到任何东西。

+0

我应该注意到,我们使用的是SLF4J使用log4j的实现。为了控制MyFaces日志记录,我们需要根据[这个myfaces问题]中的一些答案将java.util.logging重定向到slf4j(http://stackoverflow.com/questions/8012595/tomcat-logging-with- SLF4J-和log4j的)? – 2013-03-26 22:04:57

+0

在进一步调查中,SLF4J的jul-to-slf4j桥看起来并不是我们想要的,因为即使日志记录关闭,它也会影响性能。 (请参阅此处的[性能说明](http://www.slf4j.org/legacy.html#jul-to-slf4j)) – 2013-03-27 16:08:27

回答

2

我能够自己解决这个问题。

我查看了产生这些警告的MyFaces组件的源代码(e.g. grepcode source link for HtmlResponseWriterImpl)。从源代码可以看出,在打印这些警告之前,没有其他配置参数被检查。但是当然,java.util.logging级别被检查。因此,解决方案只需配置java.util.logging(又名jul或jdk日志记录)来抑制这些组件的警告。

我本可以尝试在我们的WebSphere实例中配置jdk日志记录配置文件,但这在我们的生产环境(共享基础架构,锁定服务器)中部署&更加困难。所以我结束了使用Java的解决方案 - 这是我注册为一个Spring bean类,它的init方法改变logger名称的日志记录级别它提供:

<bean id="setJdkLoggingToSevere" class="ca.mycompany.myapp.util.JdkLoggingLevelConfigurer" init-method="init"> 
    <property name="level" value="SEVERE" /> 
    <property name="loggerNames"> 
     <list> 
      <value>org.apache.myfaces.shared.renderkit.html.HtmlResponseWriterImpl</value> 
      <value>org.apache.myfaces.renderkit.html.HtmlImageRenderer</value> 
      <value>org.apache.myfaces.renderkit.html.ext.HtmlImageRenderer</value> 
      <value>org.apache.myfaces.shared.renderkit.html.HtmlImageRendererBase</value> 
      <value>org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlImageRendererBase</value> 
      <value>org.apache.myfaces.renderkit.html.HtmlLabelRenderer</value> 
      <value>org.apache.myfaces.renderkit.html.HtmlGridRenderer</value> 
      <value>org.apache.myfaces.renderkit.html.ext.HtmlGridRenderer</value> 
      <value>org.apache.myfaces.shared.renderkit.html.HtmlGridRendererBase</value> 
      <value>org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlGridRendererBase</value> 
      <value>org.apache.myfaces.shared.renderkit.html.HtmlRendererUtils</value> 
      <value>org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils</value> 
     </list> 
    </property> 
</bean> 

这里的相关方法从我JdkLoggingLevelConfigurer类(注myLogger是SLF4J记录器,因为SLF4J是我的应用程序的日志框架):

public void init() { 
    if (this.getLoggerNames() != null) { 

     Level level = Level.parse(this.getLevel()); 

     for (String loggerName : loggerNames) { 
      Logger logger = Logger.getLogger(loggerName); 
      if (logger != null) { 
       myLogger.info("setting jdk logging for {} to {}", loggerName, level); 
       logger.setLevel(level); 
       this.loggers.add(logger); 
      } 
      else { 
       myLogger.warn("unable to set jdk logging for {} to {} because logger was null", 
         loggerName, this.getLevel()); 
      } 
     } 
    } 
} 

通过以上的地方,我们再也看不到警告消息。如果我错过了任何发出警告的myfaces组件(我最初确实错过了一些),它们可以很容易地添加到弹簧配置中。

0

在HtmlImageRendererBase的JUL记录器的使用,所以一个简单的文件添加logging.properties到类路径中包括以下行:

org.apache.myfaces.shared.renderkit.html.HtmlImageRendererBase.level = SEVERE 
+0

在共享服务器上“向类路径添加文件”不一定非常简单声音。它会将文件包含在我的WAR的WEB-INF/classes目录中吗?如果是这样,那将不会与服务器上的其他应用程序发生冲突,并且会是一个很好的解决方案。 (当然,我需要添加几行到logging.properties - 根据我的解决方案下面的许多Renderer类。) – 2013-10-08 14:16:07

+0

好吧,理解:在我的环境中,将此条目添加到日志记录中就足够了。在WEB-INF/classes中的属性 - 但我不知道这是否会在共享服务器中工作。 – 2013-10-09 15:11:08