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