Chainsaw

From Resin 3.0

Jump to: navigation, search

Apache Chainsaw is a logging visualizer for Java. Even though it is based on the Log4j framework, it is possible to use it with Resin's java.util.logging infrastructure. All that is necessary is to send Resin's log events to Chainsaw.

Register the Log Handler

First we need a small piece of Java to register a SocketHandler, formatted with an XMLFormatter. This handler will connect to Chainsaw and send log events. Here's a simple example:

 package com.caucho.example;
 
 import javax.annotation.PostConstruct;
 import java.io.*;
 import java.util.logging.*;
 
 public class ChainsawHandler {
   private String _host = "localhost";
   private int _port = 4448;
   private String _name;
 
   public void setHost(String host)
   {
     _host = host;
   }
 
   public void setPort(int port)
   {
     _port = port;
   }
 
   public void setName(String name)
   {
     _name = name;
   }
 
   @PostConstruct
   public void init()
     throws IOException
   {
     Logger logger = Logger.getLogger(_name);
 
     SocketHandler handler = new SocketHandler(_host, _port);
     handler.setFormatter(new XMLFormatter());
 
     logger.addHandler(handler);
 
     System.err.println("added " + handler + " to " + logger);
   }
 }

Compile this class, create a jar, and copy the jar to ${resin.root}/ext-lib. Now to get this code to run on startup, just add the following to your resin.xml configuration:

 <cluster id="app-tier">
 
   <example:ChainsawHandler xmlns:example="urn:java:com.caucho.example">
     <ejb:Startup xmlns:ejb="urn:java:javax.ejb"/>
 
     <example:name>com.caucho</example:name>
     <example:host>localhost</example:host>
     <example:port>4448</example:port>
   </example:ChainsawHandler>

Adjust the host, port, and logger name as you like.

Configure Chainsaw

To configure Chainsaw to accept the log events from Resin, we'll need to add a new Receiver:

  1. Start Chainsaw
  2. Select "Let me define Receivers manually"
  3. Just right click on the Receivers menu on the right
  4. Select "New XMLSocketReceiver..."
  5. In the XMLSocketReceiver dialog box, change the value of the "decoder" property to "org.apache.log4j.xml.UtilLoggingXMLDecoder"
  6. Set the name to "ResinReceiver"
  7. Adjust the port to match the one you set above in the Resin configuration (default is 4448)
  8. Click Ok
  9. Start Resin... you should see Resin's startup logs in Chainsaw!
Personal tools