Using Chainsaw for Log Viewing

If you’re a programmer, no doubt you’ve the occasional, if not constant, need to read the logging statements generated by your application. I know that I’m constantly reading log output, which is why I’m thankful for a tool like Chainsaw v2. Despite having a not-yet-complete feel to it, Chainsaw has become an invaluable tool in my programming environment. Recently I discovered a hint that I should have known a long time ago, which increases its usability tenfold.

Configuring log4j and Chainsaw is a breeze. Once you’ve downloaded it, configure your log4j to use a SocketAppender. Here’s a snippet from my own log4j.properties:

log4j.logger.com.spider=DEBUG, CHAIN
log4j.appender.CHAIN=org.apache.log4j.net.SocketAppender
log4j.appender.CHAIN.remoteHost=localhost
log4j.appender.CHAIN.port=4238
log4j.appender.CHAIN.locationInfo=false

Here I’ve set up an appender named ‘CHAIN’ on port 4238. Its running on the same machine as my application (hence ‘localhost’), but it could just as easily point to a Chainsaw instance on another computer.

Next, add a “SocketReciever” within Chainsaw. The important property is ‘port’, which must correspond the value in your log4j.properties:

Chainsaw receiver configuration

That’s it. Your log messages should go to chainsaw, where you can navigate and search with ease. Here are a couple tips for Chainsaw use, including my own recent discovery:

  • Create an XML receiver file and configure Chainsaw to use it upon startup. This way you won’t have to redefine the receiver each time. See “View example Receiver configuration” on Chainsaw’s welcome tab.
  • Use the ‘Refine Focus’ field when you need to get at specific log statement or logger. You can use the “=~” operand for partial matches. For example, if you want to display only log messages from the Logger named “ServiceClassWithLotsOfLogging”, you can type “Logger ~= LotsOf” in refine focus. This same technique can be used for messages as well: “msg ~= some logging text”. Wish I had known this a long time ago!

If you’ve multiple monitors (or computers), I think you’ll find that 2nd monitor makes a great home for Chainsaw.

Happy coding!

~ Keith

4 thoughts on “Using Chainsaw for Log Viewing

  1. I just saw a demonstration of chainsaw today and it was pretty neat. Traditional logging goes right to a text file. This sends the loging to a program (chainsaw) where you can search and filter the logs.

  2. I’m going to have to be honest here. I really don’t understand what benefit Chainsaw has over searching in a plain old text editor. In Chainsaw you have to use Perl expressions to parse through the results “msg ~= some logging text”. In my text editor I can just type in “some logging text” anad I’m good to go. My text editor (I use EditPlus) also supports entering regular expressions if I want to search that way.

    If formatting is the issue, Log4J has built in support for writing to HTML files, which can be easier to read.

  3. The biggest benefit of Chainsaw is with multiple applications in a stack, with many many threads you can set, at runtime, your search criteria with business parameters and thread ids and follow the execution of a process for debugging. Excellent when using things like an ESB and web servers etc.

  4. Thanks a lot. Simple and clear explanation which works.
    I’ve been googling for over an hour for this.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>