Use log messages in the Batch Processor

Use log messages in the Batch Processor

The Batch Processor provides feedback through log messages. While basic progress details are logged to the console, the Batch Processor can be configured using log4j (or log4net for the .NET version), to provide more verbose details, or to log details to different destinations.

For more information, go to:

http://logging.apache.org/log4j/1.2/index.html

http://logging.apache.org/log4net/

 

Note: If you wish to write Batch Processor logs to a database, you will need to consult the documentation for the chosen appender regarding what you will need to do to escape special characters like single quotes (') and commas (,).

Basic Progress

Basic progress information is always logged to the console. This information provides progress indicators during processing, and a brief summary that includes the number of cases processed, number of cases ignored and total time taken, once processing has been completed.

Java - log4j configuration

There is a default log4j.xml file inside the determinations-batch.jar file. The logging level is set to "warn" and send output to the console. If a log4j.xml file is placed in the working directory of the Batch Processor, that file will be used instead of the default configuration.

.NET - log4net configuration

The .NET runtime comes with a log4net configuration file (log4net.xml).The debugging level is set to "warn" and send output to the console.

Note: You should change this file (or replace it with one of your own). You should also ensure that the log4net.xml is in the working directory when executing the batch process.

Named Loggers

To allow for specific categories of information to be easily separated from the rest of the logged information, the Batch Processor uses the following log categories:

 

Log messages for these categories are filtered and logged according to the default log configuration described above. If a custom log configuration file is provided, the logging level and destination can be changed. The example below is of a custom log4j configuration for Java.

Case ID Field for Case Errors and Case Warnings

Messages logged to the CASE_ERROR and CASE_WARNING categories described above are attributed to individual cases. The identity of the case is included in the message itself, but to allow for simpler parsing the case identity can also be accessed from a custom log field named CaseID. This custom log field can be included in the layout of a configured appender with the syntax %X{CaseID}.

Example

The following is an example of a custom log4j configuration for Java; you will notice that the logging in this example has been configured to:

  1. Set the logging threshold of the MAIN category to "info" and log messages to a file named "case-main.log"
  2. Set the logging threshold of the CASE_ERROR category to "error" and log messages to a file named "case-error.log"
  3. Set the logging threshold of the CASE_WARN category to "warn" and log messages to a file named "case-warn.log"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> 
<log4j:configuration>
    <appender name="console" class="org.apache.log4j.ConsoleAppender"> 
        <layout class="org.apache.log4j.PatternLayout"> 
            <param name="ConversionPattern" value="%p %t %c - %m%n" /> 
        </layout> 
    </appender> 
      
    <appender name="case-main-log" class="org.apache.log4j.FileAppender"> 
        <param name="File" value="case-main.log" /> 
        <param name="Threshold" value="info" /> 
        <layout class="org.apache.log4j.PatternLayout"> 
            <param name="ConversionPattern" value="%t - %m%n" /> 
        </layout> 
    </appender> 
    
    <appender name="case-error-log" class="org.apache.log4j.FileAppender"> 
        <param name="File" value="case-error.log" /> 
        <param name="Threshold" value="error" /> 
        <layout class="org.apache.log4j.PatternLayout"> 
            <param name="ConversionPattern" value="%t - %m%n" />  
        </layout> 
    </appender> 
    
    <appender name="case-warn-log" class="org.apache.log4j.FileAppender"> 
        <param name="File" value="case-warn.log" /> 
        <param name="Threshold" value="warn" /> 
        <layout class="org.apache.log4j.PatternLayout"> 
            <param name="ConversionPattern" value="%t - %m%n" /> 
        </layout>
    </appender> 
 
    <category name="MAIN" additivity="false"> 
        <priority value="info" />
        <appender-ref ref="case-main-log" /> 
    </category> 

    <category name="CASE_ERROR" additivity="false"> 
        <priority value="error" /> 
        <appender-ref ref="case-error-log" /> 
    </category> 
 
    <category name="CASE_WARNING" additivity="false">  
        <priority value="warn" /> 
        <appender-ref ref="case-warn-log" /> 
    </category> 

    <root> 
        <priority value="warn" /> 
        <appender-ref ref="console" /> 
    </root>
 </log4j:configuration>