JXSE 2.5 : What's Cool #7 -- Logging

JXSE (JXTA for Java SE/EE 5.0) 2.5 contains quite a number of exciting changes for JXTA application developers. This little series will look at a few of the important changes in the upcoming release.

One of the first major changes to occur in the JXSE 2.5 development cycle was our transition from Log4J to java.util.logging. I previously blogged here how we used Jackpot to do the conversion between the two APIs. The instigator of our transition to use java.util.logging was the Shoal project. Since all of Glassfish already used java.util.logging they quite reasonably didn't want a second logging framework, Log4J, in order to use JXTA. This concern has been an occasional, but common, observation by JXTA deployers ever since java.util.logging first appeared in JDK 1.4. We've planned on changing to java.util.logging "eventually" for quite a while. The gentle nudge, and the offer of testing assistance from the Shoal, finally made doing the conversion a priority.

Following the conversion to java.util.logging the JXSE community has struggled a bit with the transition. The control mechanisms for java.util.logging are somewhat different from the Log4J controls and certainly not as familiar. Most of the initial bumps have smoothed out over the last nine months as the wikis, FAQs and mailing list archives have accumulated our increasing experience with java.util.logging.

As with any significant change there are inevitably comprises. Leaving Jog4J meant we lost the use of Chainsaw though we gained significantly with the availability of a wide variety of JMX tools.

During the entire life of the JXSE project we've regularly received requests to entirely disable logging including permanently disabling logging by removing it from the compiled code. Generally the request is made for two reasons; to reduce the size of the JXSE jar or to make it harder for end users to disassemble proprietary JXTA-based applications. With the change to java.util.logging it is now possible to selectively disable logging. The instructions are available as part of the JXSE 2.5 Javadoc (Which will be here once the page is updated for JXSE 2.5).

Comments:

You didn't actually lose the ability to use Chainsaw - Chainsaw can be used to process java.util.logging-initiated events in both real-time and non-realtime. For those who don't know, Chainsaw is available via Web Start here: http://logging.apache.org/log4j/docs/chainsaw.html - click the 'download' link.

Options:

1. realtime processing of events over TCP
2. realtime (or non-realtime) processing of a regular text log file
3. non-realtime processing of an XMLFormatter-formatted log file

Option 1. configure the JUL side to use a SocketHandler (with the default XMLFormatter). On the Chainsaw side, specify this xml file in the global application preferences/configuration URL field (change the port on both sides as needed):

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration
xmlns:log4j="http://jakarta.apache.org/log4j/"
debug="true">

<plugin name="UtilLoggingSocketReceiver"
class="org.apache.log4j.net.XMLSocketReceiver">
<param name="Port" value="4448"/>
<param name="decoder"
value="org.apache.log4j.xml.UtilLoggingXMLDecoder"/>
</plugin>
<root>
<level value="debug"/>
</root>
</log4j:configuration>

Option 2: On the JUL side, log to a regular text file using a FileHandler and a SimpleFormatter. On the Chainsaw side, specify a LogFilePatternReceiver in the configuration - here's an example (you'll have to modify the fileURL, logFormat and possibly timestampFormat fields to match the formatter used by FileHandler):

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
debug="true">

<plugin name="fileReceiver"
class="org.apache.log4j.varia.LogFilePatternReceiv er">
<param name="fileURL" value="file:///C:/somelog.txt"/>
<param name="timestampFormat" value="yyyy-MM-dd HH:mm:ss,SSS"/>
<param name="logFormat" value="TIMESTAMP LEVEL CLASS - PROP(USER) -
MESSAGE"/>
<param name="name" value="testLog"/>
<param name="tailing" value="true"/>
</plugin>

<root>
<level value="debug"/>
</root>
</log4j:configuration>

Option 3: On the JUL side, use a FileHandler with the default XMLFormatter. On the Chainsaw side, when you want to load in the file, use the file-load java util file menu and specify the file containing the events.

Hope this helps...

Posted by Scott Deboy on October 14, 2007 at 02:02 PM PDT #

This is fantastic news Scott! It doesn't appear that the JXSE wiki pages have yet been updated for java.util.logging. It would be great if these instructions were part of the updated page.

Posted by Mike Duigou on October 15, 2007 at 08:49 AM PDT #

Post a Comment:
Comments are closed for this entry.
About

mduigou

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today