Differences between revisions 10 and 11
This is also important to take note of since the ChainsawLogFileRecieverState.xml file we configure Chainsaw with needs to know what this is set at (with slightly diffrent syntax just to make things fun). * The value Attribute uspecifies the format in which the log will be written to the log file.
This is also important to take note of since the ChainsawLogFileRecieverState.xml file we configure Chainsaw with needs to know what this is set at (with slightly diffrent syntax just to make things fun). Line 20: Line 33: Line 21: Line 35:   Line 24: Line 38:                                                         Line 31: Line 45:        Line 34: Line 48:                              Line 38: Line 52:                                                  Line 46: Line 60: Line 51: Line 63: * The syntax is valid * The syntax is valid Line 57: Line 69: 1. log4j:configuration/plugin/param@fileURL's value attribute in ChainsawLogFileRecieverState.xml points to the same log file that log4j.xml's log4j:configuration/appender/param@File does. 1. log4j:configuration/plugin/param@fileURL's value attribute in ChainsawLogFileRecieverState.xml points to the same log file that log4j.xml's log4j:configuration/appender/param@File does. Line 59: Line 71: 1. Make sure that the timestampFormat that is being output in the log matches the one in ChainsawLogFileRecieverState.xml at log4j:configuration/plugin/param@timestampFormat 1. Make sure that the timestampFormat that is being output in the log matches the one in ChainsawLogFileRecieverState.xml at log4j:configuration/plugin/param@timestampFormat Line 61: Line 73: 1. Note that the ChainsawLogFileRecieverState.xml log4j:configuration/plugin/param@logFormat value matches the log4j.xml log4j:configuration/appender/layout/param@ConverstionPattern, and if that doesn't make sense see the table bellow.||||||<:#999999>'''Log4j/Chainsaw Pattern Layout Integration Table'''||||<#BBBBBB>'''[[http://logging.apache.org/log4j/docs/api/org/apache/log4j/PatternLayout.html|log4j.xml PatternLayout]]'''||<#BBBBBB>'''[[http://logging.apache.org/log4j/docs/api-1.3/org/apache/log4j/varia/LogFilePatternReceiver.html|ChainsawLogFileRecieverState.xml]]'''||<:#BBBBBB>'''Description'''||||<#a1b7d9>%d||<#a1b7d9>TIMESTAMP||<#a1b7d9>Used to output the date of the logging event||||%-5p||LEVEL||Used to output the priority of the logging event||||<#a1b7d9>%t||<#a1b7d9>THREAD||<#a1b7d9>Used to output the name of the thread that generated the logging event.||||%C||CLASS||Used to output the fully qualified class name of the caller issuing the logging request||||<#a1b7d9>%F||<#a1b7d9>FILE||<#a1b7d9>Used to output the file name where the logging request was issued.||||%L||LINE||Used to output the line number from where the logging request was issued.||||<#a1b7d9>%m||<#a1b7d9>MESSAGE||<#a1b7d9>Used to output the application supplied message associated with the logging event.||||%n|| n/a ||Outputs the platform dependent line separator character or characters.||||<#a1b7d9>%x||<#a1b7d9> LOGGER ||<#a1b7d9> The logger from which the message came|| 1. Note that the ChainsawLogFileRecieverState.xml log4j:configuration/plugin/param@logFormat value matches the log4j.xml log4j:configuration/appender/layout/param@ConverstionPattern, and if that doesn't make sense see the table bellow.||||||<#999999 style="text-align:center">'''Log4j/Chainsaw Pattern Layout Integration Table''' ||||<#BBBBBB>'''[[http://logging.apache.org/log4j/docs/api/org/apache/log4j/PatternLayout.html|log4j.xml PatternLayout]]''' ||<#BBBBBB>'''[[http://logging.apache.org/log4j/docs/api-1.3/org/apache/log4j/varia/LogFilePatternReceiver.html|ChainsawLogFileRecieverState.xml]]''' ||<#BBBBBB style="text-align:center">'''Description''' ||||<#a1b7d9>%d ||<#a1b7d9>TIMESTAMP ||<#a1b7d9>Used to output the date of the logging event ||||%-5p ||LEVEL ||Used to output the priority of the logging event ||||<#a1b7d9>%t ||<#a1b7d9>THREAD ||<#a1b7d9>Used to output the name of the thread that generated the logging event. ||||%C ||CLASS ||Used to output the fully qualified class name of the caller issuing the logging request ||||<#a1b7d9>%F ||<#a1b7d9>FILE ||<#a1b7d9>Used to output the file name where the logging request was issued. ||||%L ||LINE ||Used to output the line number from where the logging request was issued. ||||<#a1b7d9>%m ||<#a1b7d9>MESSAGE ||<#a1b7d9>Used to output the application supplied message associated with the logging event. ||||%n ||n/a ||Outputs the platform dependent line separator character or characters. ||||<#a1b7d9>%x ||<#a1b7d9>LOGGER ||<#a1b7d9>The logger from which the message came || Line 76: Line 91: Line 78: Line 94: Line 83: Line 99:              Line 86: Line 102:

Note: The latest developer snapshot of Chainsaw (available at http://people.apache.org/~sdeboy) can automatically build a Chainsaw configuration from existing fileappender entries - the process described below still works, but if you want to use the Chainsaw UI to build a configuration from an existing log4j.xml or log4j.properties, you can do that.

## Automatic configuration

To automatically generate a Chainsaw configuration from an existing log4j.xml or log4j.properties file with fileappender entries, download the developer snapshot of Chainsaw (link above), then:

• Choose the 'Use fileappender entries from a log4j config file' option
• Select the 'Open File...' button and navigate to your file
• This configuration won't be persisted unless you choose the 'Save configuration as...' button and provide a file name
• You can choose the 'Always start Chainsaw with this configuration' checkbox if this is the only configuration you will use
• If you use multiple configurations, you can pass the URL to the Chainsaw configuration file in the chainsaw shell script or chainsaw.bat:

## Manual configuration

Two files need to be configured to make the log4 RollingFileAppender work with Chainsaw

• Log4j Files
1. log4j.xml
• Chainsaw Files

## log4j.xml

This file is of course used to configure the output from the log in log4j. The following are steps on how to configure it.

1. Take special note in log4j.xml bellow of the log4j:configuration/appender/param@File
2. Also take note in log4j.xml bellow of the log4j:configuration/appender/layout/param@ConverstionPattern

• The value Attribute uspecifies the format in which the log will be written to the log file. <br/> This is also important to take note of since the ChainsawLogFileRecieverState.xml file we configure Chainsaw with needs to know what this is set at (with slightly diffrent syntax just to make things fun).

log4j.xml - Some where in whatever you are logging with this.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC "-//log4j/log4j Configuration//EN" "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

<appender name="FILE_APPENDER"
class="org.apache.log4j.RollingFileAppender">
<param name="File" value="c:/dev/logs/serverLog.log" />
<param name="Append" value="true" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
</layout>
</appender>

<logger name="com.package.logger.LogClass">
<level value="DEBUG"/>
</logger>

<root>
<level value="ERROR" />
<appender-ref ref="FILE_APPENDER"/>
</root>

</log4j:configuration>

## ChainsawLogFileRecieverState.xml

This is the file we are going to use to configure Chainsaw to read the log file output by log4j that we configured above. It isn't neccesary that we call it ChainsawLogFileRecieverState.xml, it can be called anything as long as:

• The syntax is valid
• The file has a .xml extention
• When Chainsaw is started and the "Warning: You have no Receivers defined..." dialog is displayed, the "Let me Search for a configuration file" is selected, and the file (in our example ChainsawLogFileRecieverState.xml) is selected using the browse button.

The following are a few things to note as it is being configured.

1. log4j:configuration/plugin/param@fileURL's value attribute in ChainsawLogFileRecieverState.xml points to the same log file that log4j.xml's log4j:configuration/appender/param@File does.

2. Make sure that the timestampFormat that is being output in the log matches the one in ChainsawLogFileRecieverState.xml at log4j:configuration/plugin/param@timestampFormat

3. Note that the ChainsawLogFileRecieverState.xml log4j:configuration/plugin/param@logFormat value matches the log4j.xml log4j:configuration/appender/layout/param@ConverstionPattern, and if that doesn't make sense see the table bellow.

 Log4j/Chainsaw Pattern Layout Integration Table Description %d TIMESTAMP Used to output the date of the logging event %-5p LEVEL Used to output the priority of the logging event %t THREAD Used to output the name of the thread that generated the logging event. %C CLASS Used to output the fully qualified class name of the caller issuing the logging request %F FILE Used to output the file name where the logging request was issued. %L LINE Used to output the line number from where the logging request was issued. %m MESSAGE Used to output the application supplied message associated with the logging event. %n n/a Outputs the platform dependent line separator character or characters. %x LOGGER The logger from which the message came

Also click the headers in this table for reference on where I got this information.

ChainsawLogFileRecieverState.xml - File read by Chainsaw

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration PUBLIC "-//log4j/log4j Configuration//EN" "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true">

</log4j:configuration>