Configuration

log4j provides extensive support for configuring the destination of the trace information. This section does not attempt to duplicate the log4j documentation but places this information in the context of IBM Cúram Social Program Management. The configuration information should be placed in a file pointed at by the curam.trace.configfile.location property.

If the curam.trace.configfile.location property is not set, the default log4j setting is to use a Console Appender. The Console Appender simply outputs everything output at the default (or higher) log4j level to System Out. The default log4j level for the top level logger (and all inherited loggers) is set to DEBUG.1

Configuration will result in trace information being written to a rolling file appender. This means the output is placed in a file until it reaches a specified size. Once it reaches this size it is "rolled-over", and it is renamed by appending a .1 to the file name. If a .1 file exists it is first renamed to .2 and so on.

This is suitable for development environments where a historical trace can be useful.

Figure 1. Configuring log4j
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!--
   | For more configuration information and examples
   | see the Jakarta Log4j website:
   | http://jakarta.apache.org/log4j
-->

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

  <!-- ========================== -->
  <!-- Append messages to a File -->
  <!-- ========================== -->
  <appender name="OutputToFile"
            class="org.apache.log4j.RollingFileAppender">
    <param name="File"
           value="d:/CuramProps/CuramAppLog.log" />
    <param name="Threshold"
           value="debug"/>
    <param name="MaxBackupIndex"
           value="3"/>

    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern"
           value="[%-5p] [%d{dd MMM yyyy HH:mm:ss}] [%c] - %m%n"/>
    </layout>
  </appender>

  <!-- ======================= -->
  <!-- Setup the Root category -->
  <!-- ======================= -->
  <root>
    <level value="INFO"/>
    <appender-ref ref="OutputToFile"/>
  </root>

</log4j:configuration>

There are a number of customizable values in this file:

However, direct access to a file may not be an ideal mechanism if the trace output should be monitored. Configuration will result in trace information being written to a socket. A listener (such as Apache Chainsaw which is delivered with log4j) can then be used to display the resultant information.

Figure 2. Configuring log4j to log to a socket
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!--
   | For more configuration information and examples
   | see the Jakarta Log4j website:
   | http://jakarta.apache.org/log4j
-->

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

  <!-- =========================== -->
  <!-- Append messages to a Socket -->
  <!-- =========================== -->
  <appender name="OutputToSocket
            class="org.apache.log4j.net.SocketAppender">
    <param name="RemoteHost"
           value="localhost" />
    <param name="Port"
           value="4445"/>

    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern"
          value="[%-5p] [%d{dd MMM yyyy HH:mm:ss}] [%c] - %m%n"/>
    </layout>
  </appender>

  <!-- ======================= -->
  <!-- Setup the Root category -->
  <!-- ======================= -->
  <root>
    <level value="INFO"/>
    <appender-ref ref="OutputToFile"/>
  </root>

</log4j:configuration>

The Conversion pattern used in this file is the same but some extra customizable values have been introduced:

Numerous other possibilities exist for this configuration and this section does not attempt to duplicate the existing log4j documentation. However, it is worth noting that Nested Diagnostic Contexts are not currently supported.

1 The set of possible levels (in order of priority) defined by log4j are ALL, DEBUG, INFO, WARN, ERROR, FATAL and OFF. Only those items logged at the specified level or higher levels will be included in the log.