25

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
Betlista
  • 10,327
  • 13
  • 69
  • 110

2 Answers2

26

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.

Betlista
  • 10,327
  • 13
  • 69
  • 110
Yishai
  • 90,445
  • 31
  • 189
  • 263
  • I found this question and answer very confusing. I believe the question has been edited a few times so this answer is now quite misleading. Certainly if I use the given log4j xml I do _not_ get any INFO or DEBUG Quartz messages coming out - they are restricted to FATAL. Note: I tested this in a standalone program, not in JBoss, so I dunno if JBoss does something clever/different with log4j. – davidfrancis Jun 17 '13 at 20:30
  • @davidfrancis, JBoss probably sets the root level to something different than you are in your standalone. I think the question and answer are still valid. – Yishai Jun 17 '13 at 20:46
  • Fair enough, if the question and answer is seen as JBoss specific then I think you're right. The problem is that the question is quite general. Got me very confused but that's nothing too new ;] – davidfrancis Jun 20 '13 at 09:54
4

Move "<appender-ref ref="CONSOLE"/>" from <root> to <category name="com.foo.bar">.

I.e.:

<category name="com.foo.bar">
  <priority value="DEBUG"/>
  <appender-ref ref="CONSOLE"/>
</category>   

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

With the config that you show the console shouldn't get any debug messages so check if any other config could be used or if some code is programatically changing the config.

Betlista
  • 10,327
  • 13
  • 69
  • 110
James A. N. Stauffer
  • 2,649
  • 3
  • 22
  • 32
  • I updated the question with the full config and some of the example output of what I'm talking about. –  Jun 25 '09 at 15:23
  • Just because JBoss reloads it doesn't mean that it is what is used. See debug to true for the root element of log4j and the output may help you see what is going wrong. – James A. N. Stauffer Jun 26 '09 at 19:29
  • Thanks ... its works fine with this suggestion.. My problem has resolved after removing the appender declaration from tag. – Gunjan Shah Aug 13 '12 at 11:28