This chapter explains how to use the tracing mechanism to help you trace or debug the Java Dynamic Management Kit (Java DMK) API. The tracing mechanism gives you internal runtime information, and you can specify the information type and level of trace and debug information you want to receive.
The proprietary tracing mechanism classes described in this chapter are all deprecated as of Java DMK 5.1. These classes have all been superseded by the java.util.logging classes that are now supported by the Java Management Extensions (JMX). How to activate logging using the java.util.logging API is explained in 4.1 Activating the java.util.logging API. The information contained in the rest of this chapter is deprecated and is retained for purposes of backwards compatibility only.
To activate traces using the standard java.util.logging API, you must edit, or copy and edit, the template.logging.properties file that is provided by Java DMK in the directory installDir/etc/conf/.
You must uncomment the categories from which you want to obtain traces, and the level of tracing you require. Then pass the file on the command line when starting your Java classes, as follows
$ java -Djava.util.logging.config.file=Path_to_logging.properties_file Java_class |
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);
It is possible to specify the type of trace and debug information you want to receive. The following types are specified.
INFO_MBEANSERVER: information about the MBean server
INFO_MLET: information from an m-let service
INFO_MONITOR: information from a monitor
INFO_TIMER: information from a timer
INFO_ADAPTOR_CONNECTOR: information concerning all adaptors and connectors
INFO_ADAPTOR_HTML: information from an HTML adaptor
INFO_CONNECTOR_RMI: information from a RMI connector
INFO_CONNECTOR_HTTP: information from HTTP connectors
INFO_CONNECTOR_HTTPS: information from HTTPS connectors
INFO_ADAPTOR_SNMP: information from an SNMP adaptor
INFO_DISCOVERY: information from a discovery service
INFO_SNMP: information from an SNMP manager service
INFO_NOTIFICATION: information from notification mechanism
INFO_HEARTBEAT: information from heartbeat mechanism
INFO_RELATION: information from relation service
INFO_MODELMBEAN: information from the model MBean components
INFO_MISC: information sent from any other classes
INFO_ALL: information from all classes
The preceding information is held by the TraceTags class
The level of detail controls the number of messages you receive. The trace level is the default that 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 DMK implementation. If this level is specified, the information of LEVEL_TRACE is sent too. It is possible to specify the level of trace or debug information you want to receive. Two levels of information are specified in the TraceTags class.
Provides information to help a developer when programming
Provides information to help diagnose Java DMK implementation
If you choose the second option, you automatically receive all trace information as well as debug information. By default, the level is set to LEVEL_TRACE.