log4j appender阈值和类别 [英] log4j appender threshold and category

查看:208
本文介绍了log4j appender阈值和类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我先说这个问题,说我已经用尽了谷歌,或至少我一直在试图搜索。 log4j阈值,log4j阈值类别,log4j appender阈值类别等。但我真的不明白我从Google收回的结果。



这是我给出的完整配置。我不知道如何修改它以适应我的需要。

 <?xml version =1.0encoding =UTF-8?> 
<!DOCTYPE log4j:configuration SYSTEMlog4j.dtd>

<! - ===================================== ============================ - >
<! - - >
<! - Log4j配置 - >
<! - - >
<! - ========================================= ========================== - >

<! - $ Id:jboss-log4j.xml 62403 2007-04-18 15:26:43Z dimitris@jboss.org $ - >

<! -
|有关更多配置信息和示例,请参阅Jakarta Log4j
| owebsite:http://jakarta.apache.org/log4j
- >

< log4j:configuration xmlns:log4j =http://jakarta.apache.org/log4j/debug =false>

<! - ============================= - >
<! - 保存本地文件中的邮件 - >
<! - ============================= - >

< appender name =FILEclass =org.jboss.logging.appender.DailyRollingFileAppender>
< errorHandler class =org.jboss.logging.util.OnlyOnceErrorHandler/>
< param name =Filevalue =$ {jboss.server.log.dir} /server.log/>
< param name =Appendvalue =false/>

<! - 每天午夜滚动 - >
< param name =DatePatternvalue ='。'yyyy-MM-dd/>

< layout class =org.apache.log4j.PatternLayout>
< param name =ConversionPatternvalue =%d%-5p [%c]%m%n/>
< / layout>
< / appender>


<! - ========================== - > ;
<! - 将消息附加到控制台 - >
<! - ========================== - >

< appender name =CONSOLEclass =org.apache.log4j.ConsoleAppender>
< errorHandler class =org.jboss.logging.util.OnlyOnceErrorHandler/>
< param name =Targetvalue =System.out/>
< param name =Thresholdvalue =DEBUG/>

< layout class =org.apache.log4j.PatternLayout>
<! - 默认模式:日期优先级[类别] Message\\\
- >
< param name =ConversionPatternvalue =%d {ABSOLUTE}%-5p [%c]%m%n/>
< / layout>
< / appender>



<! - ================ - >
<! - 限制类别 - >
<! - ================ - >

< category name =com.arjuna>
< priority value =FATAL/>
< / category>

< category name =com.sun.facelets>
< priority value =ERROR/>
< / category>

< category name =jacorb>
< priority value =FATAL/>
< / category>

< category name =javax.enterprise.resource>
< priority value =WARNING/>
< / category>

< category name =javax.enterprise.resource.webcontainer.jsf>
< priority value =WARNING/>
< / category>

< category name =org.apache>
< priority value =FATAL/>
< / category>

< category name =org.hibernate>
< priority value =FATAL/>
< / category>

< category name =org.jboss>
< priority value =INFO/>
< / category>

< category name =org.jboss.ejb3.EJB3Deployer>
< priority value =WARNING/>
< / category>

< category name =org.jboss.ejb3.JmxKernelAbstraction>
< priority value =WARNING/>
< / category>

< category name =org.jboss.management>
< priority value =FATAL/>
< / category>

< category name =org.jboss.serial>
< priority value =FATAL/>
< / category>

< category name =org.jboss.wsf.framework>
< priority value =FATAL/>
< / category>

< category name =org.jgroups>
< priority value =FATAL/>
< / category>

< category name =org.quartz>
< priority value =FATAL/>
< / category>
<! - ===================== - >
<! - 设置根类别 - >
<! - ===================== - >

< root>
< appender-ref ref =CONSOLE/>
< appender-ref ref =FILE/>
< / root>



< / log4j:configuration>

我不明白appender的阈值级别如何与类别进行交互。看到,我只想让com.foo.bar消息显示在控制台上。但是似乎我得到了很多,例如,org.jboss.wsf.framework是倾销DEBUG消息,即使我有一个类别的名称匹配,并设置为FATAL。



我确定我正在操作正确的配置文件,因为jboss报告它重新加载配置后,我改变它。那么如何设置类别/阈值水平呢?阈值和类别之间有什么区别?



示例输出(剪切)。为什么石英显示在控制台上,当我设置为致命的?

  2009-06-22 00:58:37,666 INFO [org.quartz.plugins.history.LoggingJobHistoryPlugin] Job JobInitializationPlugin.JobInitializationPlugin_jobInitializer执行完成在00:58:37 06/22/2009和报告:null 
2009-06-22 01:08:37,669 DEBUG [org.quartz.simpl.SimpleJobFactory]生成Job的Job实例JobInitializationPlugin.JobInitializationPlugin_jobInitializer' ,class = org.quartz.jobs.FileScanJob
2009-06-23 15:44:17,790 INFO [org.jboss.wsf.stack.jbws.NativeServerConfig] 3.0.5.GA
2009-06 -23 15:44:17,868 DEBUG [org.jboss.wsf.framework.deployment.DeploymentAspectManagerImpl] WSDeploymentAspectManagerEJB上的setDeploymentAspects
2009-06-23 15:44:17,868 DEBUG [org.jboss.wsf.framework.deployment。 DeploymentAspectManagerImpl] setDeploymentAspects on WSDeploymentAspectManagerEndpointAPI


解决方案

为什么Quartz会显示在日志记录中,您将不得不更改Quartz配置如下:

 < category name =org.quartzadditivity =false> 
< priority value =FATAL/>
< / category>

additivity属性指示log4j重写根设置,并仅将它用于org.quartz。 p>

在前面提到的问题中,你只需要打开这些类中的那些消息,那么你必须首先将根元素中的优先级配置为致命(或甚至NO),然后它将只记录你明确打开的包/类。



要回答你的问题关于阈值如何与类别交互,基本上想它是作为发布/订阅。类别设置了记录器发布的内容,阈值设置了追加器的订阅级别。



这很复杂,事实上类别不是一件事,而是一个层次结构,所以你在一个类别上设置发布级别的事实不是整个故事。它可以在层次结构中覆盖,就像在您的情况。


Let me preface this question by saying I've exhausted Google, or at least what I've been trying to search for. "log4j threshold", "log4j threshold category", "log4j appender threshold category", etc. But I really don't understand the results I'm getting back from Google.

This is the full configuration I've been given. I can't figure out how to modify it to suit my needs.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<!-- ===================================================================== -->
<!--                                                                       -->
<!--  Log4j Configuration                                                  -->
<!--                                                                       -->
<!-- ===================================================================== -->

<!-- $Id: jboss-log4j.xml 62403 2007-04-18 15:26:43Z dimitris@jboss.org $ -->

<!--
| For more configuration infromation and examples see the Jakarta Log4j
| owebsite: http://jakarta.apache.org/log4j
 -->

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">

<!-- ================================= -->
<!-- Preserve messages in a local file -->
<!-- ================================= -->

<appender name="FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
  <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
  <param name="File" value="${jboss.server.log.dir}/server.log"/>
  <param name="Append" value="false"/>

  <!-- Rollover at midnight each day -->
  <param name="DatePattern" value="'.'yyyy-MM-dd"/>

  <layout class="org.apache.log4j.PatternLayout">
     <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
  </layout>
</appender>


<!-- ============================== -->
<!-- Append messages to the console -->
<!-- ============================== -->

<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
  <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
  <param name="Target" value="System.out"/>
  <param name="Threshold" value="DEBUG"/>

  <layout class="org.apache.log4j.PatternLayout">
     <!-- The default pattern: Date Priority [Category] Message\n -->
     <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c] %m%n"/>
  </layout>
</appender>



<!-- ================ -->
<!-- Limit categories -->
<!-- ================ -->

<category name="com.arjuna">
  <priority value="FATAL"/>
</category>   

<category name="com.sun.facelets">
  <priority value="ERROR"/>
</category>   

 <category name="jacorb">
   <priority value="FATAL"/>
 </category>

<category name="javax.enterprise.resource">
  <priority value="WARNING"/>
 </category>  

 <category name="javax.enterprise.resource.webcontainer.jsf">
    <priority value="WARNING"/>
 </category>  

 <category name="org.apache">
    <priority value="FATAL"/>
 </category>

 <category name="org.hibernate">
    <priority value="FATAL"/>
 </category>   

 <category name="org.jboss">
    <priority value="INFO"/>
 </category>

<category name="org.jboss.ejb3.EJB3Deployer">
    <priority value="WARNING" />
</category>

<category name="org.jboss.ejb3.JmxKernelAbstraction">
    <priority value="WARNING" />
</category>

<category name="org.jboss.management">
   <priority value="FATAL"/>
</category>

<category name="org.jboss.serial">
  <priority value="FATAL"/>
</category>

<category name="org.jboss.wsf.framework">
   <priority value="FATAL"/>
</category>   

<category name="org.jgroups">
   <priority value="FATAL"/>
</category>

<category name="org.quartz">
    <priority value="FATAL" />
</category>
<!-- ======================= -->
<!-- Setup the Root category -->
<!-- ======================= -->

<root>
   <appender-ref ref="CONSOLE"/>
   <appender-ref ref="FILE"/>
</root>



</log4j:configuration>

I don't understand how the appender's "threshold" level interacts with the categories. See, I only want com.foo.bar messages to show on the console. But it seems like I'm getting a lot more than that, for instance, org.jboss.wsf.framework is dumping out DEBUG messages, even though I have a category with a name that matches it and set to FATAL.

I'm certain I'm manipulating the correct config file, as jboss reports it's reloading the config after I change it. So how do I set the category/threshold levels right? What's the difference between the threshold and category?

Example output (snipped). Why does quartz show up on the console when I have it set to FATAL?

2009-06-22 00:58:37,666 INFO  [org.quartz.plugins.history.LoggingJobHistoryPlugin] Job JobInitializationPlugin.JobInitializationPlugin_jobInitializer execution complete at  00:58:37 06/22/2009 and reports: null
2009-06-22 01:08:37,669 DEBUG [org.quartz.simpl.SimpleJobFactory] Producing instance of Job 'JobInitializationPlugin.JobInitializationPlugin_jobInitializer', class=org.quartz.jobs.FileScanJob
2009-06-23 15:44:17,790 INFO  [org.jboss.wsf.stack.jbws.NativeServerConfig] 3.0.5.GA
2009-06-23 15:44:17,868 DEBUG [org.jboss.wsf.framework.deployment.DeploymentAspectManagerImpl] setDeploymentAspects on WSDeploymentAspectManagerEJB
2009-06-23 15:44:17,868 DEBUG [org.jboss.wsf.framework.deployment.DeploymentAspectManagerImpl] setDeploymentAspects on WSDeploymentAspectManagerEndpointAPI

解决方案

To answer the specific question of why does Quartz show up on the logging, you would have to change the Quartz configuration as follows:

 <category name="org.quartz" additivity="false">
    <priority value="FATAL" />
 </category>

The additivity attribute tells log4j to override the root setting and use this only for org.quartz.

In a previous version of the question you stated you only wanted those messages from those classes turned on, to do that you have to start with configuring the priority in the root element to fatal (or even NO) and then it will only log those packages/classes that you turn on explicitly.

To answer your question about how threshold interacts with category, basically think of it is as a publish/subscribe. The category sets what is published by the logger, the threshold sets the subscription level of the appender.

This is complicated slightly be the fact that category is not a single thing, but rather a hierarchy, so the fact that you set the publishing level on one category isn't the whole story. It may be overridden in the hierarchy, as it was in your case.

这篇关于log4j appender阈值和类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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