5.5. Configuring Logging Service

In JBoss log4j is used for logging. If you are not familiar with the log4j package, more information is available the Jakarta web site.
Logging is controlled from the central $JBOSS_HOME/server/PROFILE/conf/jboss-log4j.xml file. This file defines a set of appenders that specify the log files, the categories of messages the log file should contains, the message format and the level of filtering. By default, JBoss produces output to both the console and a log file (log/server.log).

Note

There are six basic log levels in log4j: TRACE, DEBUG, INFO, WARN, ERROR and FATAL. The logging threshold on the console is INFO, so that any informational messages, warning messages and error messages are returned to the console, while general debug and trace messages are only available in the log file. If no logging level is set for the server.log file, it defaults to DEBUG.
Always when demanding debug information, check the server.log file to see if there are any debug messages which might help you to track down the problem. However, be aware that just because the logging threshold allows debug messages to be displayed, that does not mean that all of JBoss produces detailed debug information for the log file. You should also consider increasing the logging limits set for individual categories.

Example 5.3. Example Log Limits

<!-- Limit JBoss categories to INFO --> 
<category name="org.jboss"> 
<priority value="INFO"/> 
</category>
In Example 5.3, “Example Log Limits”, the level of logging is set to INFO for all JBoss classes, with the exception of classes with more specific overrides. By default the root logger in the jboss-log4j.xml is set to INFO: any TRACE or DEBUG logger from any logger categories is not logged in any files or the console appenders. This setting is controlled through the jboss.server.log.threshold property. By default this is INFO. If changed to DEBUG, more detailed logging output is produced. Yuo can change this as follows:
  • Pass the -Djboss.server.log.threshold=DEBUG parameter when starting the server:
    ./run.sh -Djboss.server.log.threshold=DEBUG
    
  • Edit the <JBOSS_HOME>/jboss-as/server/<PROFILE>/conf/jboss-log4j.xml file directly:
    <root>
    <!-- Let us comment this out to set our own value 
    <priority value="${jboss.server.log.threshold}"/>-->
    <priority value="DEBUG"/>
    <appender-ref ref="CONSOLE"/>
    <appender-ref ref="FILE"/>
    </root>
    

    Note

    The <JBOSS_HOME>/jboss-as/server/<PROFILE>/conf/jboss-log4j.xml is scanned every 60 seconds (by default) on any changes. Therefore changing this file does not require a server restart.
As another example, let’s say you wanted to set the output from the container-managed persistence engine to DEBUG level and to redirect it to a separate file, cmp.log, in order to analyze the generated SQL commands. You would add the following code to the conf/jboss-log4j.xml file:
<appender name="CMP" class="org.jboss.logging.appender.RollingFileAppender"> 
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/> 
<param name="File" value="${jboss.server.home.dir}/log/cmp.log"/> 
<param name="Append" value="false"/> 
<param name="MaxFileSize" value="500KB"/> 
<param name="MaxBackupIndex" value="1"/> 
<layout class="org.apache.log4j.PatternLayout"> 
  <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/> 
</layout> 
</appender> 
<category name="org.jboss.ejb.plugins.cmp"> 
<priority value="DEBUG" /> 
<appender-ref ref="CMP"/> 
</category>
This creates a new file appender and specifies that it should be used by the logger (or category) for the package org.jboss.ejb.plugins.cmp.
The file appender is set up to produce a new log file every day rather than producing a new one every time you restart the server or writing to a single file indefinitely. The current log file is cmp.log. Older files have the date they were written added to their file names. Please note that the log directory also contains HTTP request logs which are produced by the web container.
By default the server.log appender is configured to retain log messages between server restarts. This is controlled by the Append property on the FILE appender which corresponds to the server.log file. By default this property is set to true; if you want the server.log contents to be wiped out on server restarts then you can edit the <JBOSS_HOME>/jboss-as/server/<PROFILE>/conf/jboss-log4j.xml file to set this property value to false. For example:
<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"/>
...