Differences between revisions 10 and 11
Revision 10 as of 2012-02-04 20:52:46
Size: 5284
Editor: PidSter
Comment: Spam removal
Revision 11 as of 2012-02-23 22:24:49
Size: 6757
Editor: ScottDeboy
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
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:

 * Select the File-Load Chainsaw Configuration menu item
 * 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:
  * \path\to\chainsaw\bin\chainsaw.bat file:///c:/path/to/chainsaw-config.xml

== Manual configuration ==
Line 4: Line 18:
  1. log4j.xml   1. log4j.xml
Line 7: Line 21:
  1. ChainsawLogFileRecieverState.xml   1. ChainsawLogFileRecieverState.xml
Line 10: Line 24:
This file is of course used to configure the output from the log in log4j.
The following are steps on how to configure it.
This file is of course used to configure the output from the log in log4j. The following are steps on how to configure it.
Line 14: Line 27:
   * The value Attribute specifies to which file the Appender will log. This will also be referenced bellow in ChainsawLogFileRecieverState.xml   * The value Attribute specifies to which file the Appender will log. This will also be referenced bellow in ChainsawLogFileRecieverState.xml
Line 17: Line 30:
   * 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).    * 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).
Line 20: Line 33:
Line 21: Line 35:
<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE log4j:configuration PUBLIC "-//log4j/log4j Configuration//EN" "log4j.dtd"> 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC "-//log4j/log4j Configuration//EN" "log4j.dtd">
Line 24: Line 38:
   <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">

        
<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">
Line 31: Line 45:
                </layout>
 
</appender>
                </layout>
    </appender>
Line 34: Line 48:
 <logger name="com.package.logger.LogClass">
  <level value="DEBUG"/>
 </logger>
        <logger name="com.package.logger.LogClass">
                <level value="DEBUG"/>
        </logger>
Line 38: Line 52:
 
 <root>
    <level value="ERROR" />
  <appender-ref ref="FILE_APPENDER"/>
 </root>
 

        <root>
                <level value="ERROR" />
                <appender-ref ref="FILE_APPENDER"/>
        </root>
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:
<!DOCTYPE log4j:configuration PUBLIC "-//log4j/log4j Configuration//EN" "log4j.dtd">  <!DOCTYPE log4j:configuration PUBLIC "-//log4j/log4j Configuration//EN" "log4j.dtd">
Line 83: Line 99:
     <param name="timestampFormat" value="yyyy-MM-d HH:mm:ss,SSS"/> 
     <param name="logFormat" value="TIMESTAMP LEVEL [THREAD] CLASS (FILE:LINE) - MESSAGE"/> 
     <param name="timestampFormat" value="yyyy-MM-d HH:mm:ss,SSS"/>
     <param name="logFormat" value="TIMESTAMP LEVEL [THREAD] CLASS (FILE:LINE) - MESSAGE"/>
Line 86: Line 102:
     <param name="tailing" value="true" />       <param name="tailing" value="true" />

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:

  • Select the File-Load Chainsaw Configuration menu item
  • 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.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

log4j.xml PatternLayout

ChainsawLogFileRecieverState.xml

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">

   <plugin name="logFileReceiver" class="org.apache.log4j.varia.LogFilePatternReceiver">
     <param name="fileURL" value="file:///c:/dev/logs/serverLog.log" />
     <param name="timestampFormat" value="yyyy-MM-d HH:mm:ss,SSS"/>
     <param name="logFormat" value="TIMESTAMP LEVEL [THREAD] CLASS (FILE:LINE) - MESSAGE"/>
     <param name="name" value="Reciever-name-in-Chainsaw" />
     <param name="tailing" value="true" />
   </plugin>

   <root>
      <level value="debug"/>
   </root>
</log4j:configuration>

Configuring_a_log4j_RollingFileAppender_with_Chainsaw (last edited 2012-02-23 22:24:49 by ScottDeboy)