Java Dynamic Management Kit 4.1 Tools Reference

Receiving Trace/Debug Information

The com.sun.jdmk.Trace class provides methods for receiving trace/debug messages. Options provided by this class enable you to specify:

All the classes of the Java Dynamic Management Kit use the trace class for printing traces. You can use the trace class in your own code for printing debug traces for your own classes.

Specifying the Types of Trace/Debug Information

It is possible to specify the type of trace/debug information you want to receive. The following types are specified:

Specifying the Level of Trace/Debug Information

The level of detail controls the amount of messages you receive. The "trace" level is the default which gives information about the actions of the MBean server and other components. The "debug" level includes all the "trace" information providing information to help diagnose Java Dynamic Management Kit implementation. If this level is specified, the information of LEVEL_TRACE will be sent too. It is possible to specify the level of trace/debug information you want to receive. Two levels of information are specified:

If you choose the second option you will automatically receive all trace information as well as debug information. By default, the level is set to LEVEL_TRACE.

Receiving Trace/Debug Information

The com.sun.jdmk.Trace class uses the notification mechanism to distribute the information. You must add a notification listener to receive information. See example Example 4-1. There are two ways to receive trace information:


Example 4-1 Creating a Notification Listener

// Create a listener and save all info to the file /tmp/traceInfo/ 
TraceListener listener = new TraceListener("/tmp/trace");


Example 4-2 Creating a Trace Filter

// create a trace filter with LEVEL_DEBUG and INFO_ALL/
TraceFilter filter = new TraceFilter(Trace.LEVEL_DEBUG, Trace.INFO_ALL);


Example 4-3 Adding the Notification Listener to the class

// add the listener to the class Trace/
Trace.addNotificationListener(listener, filter, null);