To receive trace and debug information you must add a notification listener to the class com.sun.jdmk.TraceManager.
You control the tracing by defining the trace properties specific to the Java DMK. Three factors affect tracing:
Various components that send trace messages
Level of detail
Output destination
The com.sun.jdmk.trace.Trace class is used to emit trace messages. All the classes of the Java DMK use this Trace class for sending traces. You can use the Trace class in your own code for producing debug traces for your own classes.
The com.sun.jdmk.TraceManager class provides methods for receiving trace and debug messages. Options provided by the TraceManager class are described in the following sections:
The com.sun.jdmk.TraceManager 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.
Adding a notification listener with a filter in the code. It is possible to have more than one notification listener but with different filters. With TraceFilter, you can specify the type and level of information you want to receive. See Example 4–2 and Example 4–3.
Specifying system properties in the command to start the Java interpreter when you run a class. In this case, the code of the class must include a call to the TraceManager method. When the TraceManager method is called, all the previously enabled trace and debug information are disabled. Only the properties currently defined when the method is called are enabled.
// Create a listener and save all info to the file /tmp/trace TraceListener listener = new TraceListener("/tmp/trace");
// create a trace filter with LEVEL_DEBUG and INFO_ALL/ TraceFilter filter = new TraceFilter(Trace.LEVEL_DEBUG, Trace.INFO_ALL);
// add the listener to the class Trace/ TraceManager.addNotificationListener(listener, filter, null);