Java Dynamic Management Kit 5.1 Tools Reference Guide

Chapter 4 Tracing Mechanism

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.


Note –

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.


4.1 Activating the java.util.logging API

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

4.2 Receiving Trace and Debug Information Using the Deprecated TraceManager

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:

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.


Example 4–1 Creating a Notification Listener

// Create a listener and save all info to the file /tmp/trace 
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/
TraceManager.addNotificationListener(listener, filter, null);

4.3 Specifying the Type of Trace and Debug Information

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

The preceding information is held by the TraceTags class

4.4 Specifying the Level of Trace and Debug Information

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.

LEVEL_TRACE

Provides information to help a developer when programming

LEVEL_DEBUG

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.