Thursday, October 01, 2009

Sending GlassFish java.util log records to Chainsaw - no problemo

To send Java log records to from GlassFish to chainsaw we need to first translate the LogRecords (from java.util.logging) to LoggingEvents (used byt the log4j framework and accepted by chainsaw). Then also need to publish the resulting LoggingEvents to Chainsaw over a socket.

Here is how I do it:

* Copy ChainsawHandler.jar and log4j.jar into GLASSFISH_HOME/domains/domain1/lib/ext

* In Glassfish admin web console under: Application Server/Logging/General/Log Handler enter:

* In Glassfish admin web console under: Application Server/JVM Settings/JVM Options/ add a new JVM Option:


this is the port to which Chainsaw clients can connect

* Restart GlassFish

* Configure a new SocketHubReceiver in Chainsaw that will connect to the chainsawPort

In case you are curious how it works or want to add functionality or fix a bug here is the source.

I would like to thank my current employer HSL for allowing me to publish this work - which they have sponsored in the form of my paycheck :)