Tuesday, July 12, 2011

LogMX


In a previous post I described some benefits of using Apache Chainsaw to help you analyze log output from log4j.  Despite some significant quality problems, I still found a useful tool while working with log4j output (hey what do you expect for free!).  I have search many times for a log viewer that is better, and there are some very good ones out there (I like LogExpert in particular).  But sadly most of them tend to be to general purpose to excel as a Java debugging tool.

FINALLY the other day I founds something better than Chainsaw.  Way better.  It's called LogMX:


LogMX that includes the nice things that I like in Chainsaw, in addition to a lot of other useful and unique features.  And importantly, LogMX is polished, rock solid, zippy, and somewhat easier to use.  Take a look at the features and screenshots.

I've only tried LogMX with log4j, but it claims it is compatible with all the major logging frameworks, in addition to any "simple" log file format.  To use LogMX with log4j, you just need to configure an appender with the HTMLLayout or XMLLayout.  For example:


        <appender name="logmx" class="org.apache.log4j.FileAppender">
                <param name="File" value="target/logmx.log" />
                <param name="Append" value="true" />
                <param name="Threshold" value="TRACE" />
                <layout class="org.apache.log4j.xml.XMLLayout"/>
        </appender>


Then from within LogMX you just do File -> Open and point it to your log file.  

One important  thing to be aware of is LogMX is a commericial program, but you can use it for free for non-commericial use, and the commericial license is not unreasonable at $99.

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>