Friday, July 1, 2011

Apache Chainsaw Jumpstart

It's a tedious job to filter and sift through log files to try to understand the complex behaviour of large systems.  Tail and grep are a good place to start, but there are many other more powerful GUI based options designed specifically for log analysis that make the job a little easier.  For java, one log viewer that I find to be useful is the venerable Apache Chainsaw.  As a GUI app,  first impressions are not great.  Chainsaw presents itself with the very unappealing classic Swing look and feel that will probably drive most users away immediately.  However, putting aesthetics aside, Chainsaw is a well thought-out app with some nice features.  


One feature I particularly like is the tree control that corresponds to the heirarichal "categories" of the log4j output, which in turn correspond to java packages.  Providing a tree control to help filter based category/package is just awesome, and I'm suprised there aren't more log viewers that apply this idea.


Chainsaw provides a number of different integration options.  I have had mixed results with SocketAppender and "Zero Touch Config" but using plain old log files works great.  The only hurdle to overcome is writing the log files in a format that Chainsaw can understand, and then configuring Chainsaw to read the file. Using a file based approach it should also be possible configure Chainsaw to read log files produced by other logging frameworks such as jdk-logging or logback.  


Here is the info you need to quickly get you started with log4j and chainsaw:


This the log4j appender configuration I use for Chainsaw. (just paste this into your log4j.xml)  This will create an additional logfile named "chainsaw.log" containing all the fields that Chainsaw expects: 


<appender name="chainsaw" class="org.apache.log4j.DailyRollingFileAppender">
    <param name="File" value="chainsaw.log" />
    <param name="DatePattern" value="'.'yyyy-MM-dd" />
    <param name="Append" value="true" />
    <param name="Threshold" value="DEBUG" />
    <layout class="org.apache.log4j.PatternLayout">
        <!-- date|category|class|file|lineno|method|priority|thread|message -->
        <param name="ConversionPattern" value="%d{ISO8601} %c %C %F %L %M %p %t %m%n" />
    </layout>
</appender>




Here's the corresponding chainsaw configuration file.  Unfortunately you have to edit this file to provide the absolute path to the chainsaw.log file.  Then from within Chainsaw you can load this configuration by doing "Load -> Load Log4j File" from the  menu.  If everything is configured properly you should see a new tab in the Chainsaw UI for your logfile.

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

       <appender name="A2" class="org.apache.log4j.ConsoleAppender">
              <layout class="org.apache.log4j.SimpleLayout" />
       </appender>

       <plugin name="LogFileReceiver" class="org.apache.log4j.varia.LogFilePatternReceiver">
              <param name="fileURL" value="file:///c:/--path-to--/chainsaw.log" />
              <param name="timestampFormat" value="yyyy-MM-dd HH:mm:ss,SSS" />
              <param name="logFormat" value="TIMESTAMP LOGGER CLASS FILE LINE METHOD LEVEL THREAD MESSAGE" />
              <param name="name" value="sampleLogFilePatternReceiver" />
              <param name="tailing" value="true" />
       </plugin>

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


3 comments:

  1. Care to try out the latest developer snapshot of Chainsaw? A ton of new features included, new config dialog (including ability to build a Chainsaw config from your log4j xml config), editable rows (marker field), search results collected in the bottom pane, etc.

    Feel free to shoot feedback to the log4j dev list or my email if you'd like.

    Mac DMG and tarball available here:

    http://people.apache.org/~sdeboy

    Thanks

    Scott

    ReplyDelete
  2. Hey, that's great! I'm glad to see someone is still working on chainsaw.

    ReplyDelete
  3. Hi,

    Can I able to filter certain events from my application log file via LogFilePatternReceiver and re-direct to another log file ?

    So, that I can read my custom log file to present it?

    Because I'm using headless Linux system

    ReplyDelete