Logging is the most important tool to troubleshoot errors and monitor the status of the components of the Platform. log4j provides a familiar, flexible framework, familiar to Java developers.
Section 4.1, “Logging Defaults” contains information about customizing the default logging behavior for the Platform. See Section 4.2, “Component-Specific Logging” for additional customization. Appendix B, Logging Information and Recipes provides some logging recipes, which you can customize to your needs.
The log4j configuration is loaded from the
JBOSS_HOME/server/PROFILE/conf/jboss-log4j.xml deployment descriptor. log4j uses appenders to control its logging behavior. An appender is a directive for where to log information, and how to do it. The jboss-log4j.xml file contains many sample appenders, including FILE, CONSOLE, and SMTP.
Table 4.1. Common log4j Configuration Directives
| Configuration Option | Description |
|---|---|
appender
|
The main appender. Gives the name and the implementing class.
|
errorHandler
|
Delegates an external class to handle exceptions passed to the logger, especially if the appender cannot write the log for some reason.
|
param
|
Options specific to the type of appender. In this instance, the <param> is the name of the file that stores the logs for the FILE appender.
|
layout
|
Controls the logging format. Tweak this to work with your log-parsing software of choice.
|
Example 4.1. Sample Appender
<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="true"/> <!-- In AS 5.0.x the server log threshold was set by a system property. In 5.1 and later, the system property sets the priority on the root logger (see <root/> below) <param name="Threshold" value="${jboss.server.log.threshold}"/> --> <!-- Rollover at midnight each day --> <param name="DatePattern" value="'.'yyyy-MM-dd"/> <layout class="org.apache.log4j.PatternLayout"> <!-- The default pattern: Date Priority [Category] (Thread) Message\n --> <param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n"/> </layout> </appender>
For more information on configuring log4j, see http://logging.apache.org/log4j/1.2/.