Show TOC Start of Content Area

Function documentation Relations Between Category and Location  Locate the document in its SAP Library structure

Use

It is common practice to look at the log and trace messages together when you perform a diagnosis. A correlation between a problematic logical area and the source code location problem is highly desired. For example, an error occurs when closing the database. The actual location of the source code (from which class, which method, with what argument(s)), is also reported.

For more information about how to generate both log and trace messages, see Message Output with Severity.

Example

This example only shows the attachment of a location to a category (it refers to the location being associated to the category, as relative of the category,) but this is also true for the opposite case.

This graphic is explained in the accompanying text

It is legitimate to associate more than one category to a location at each logging, but only one location for one category. For more information about each class, see the output method APIs of each class.

 

package com.sap.fooPackage;

 

import com.sap.tc.logging.*;

 

public class Node {

   private static final Location loc =

      Location.getLocation("com.sap.fooPackage.Node");

   private static final Category objMgmt =

      Category.getCategory("/Objects/Management");

   public void announce(Object o) {

      final String method = "announce(java.lang.Object)";

      loc.entering(method, new Object[] { o });

      try {

         // Register object ...

      }

      catch (RegistrationException e) {

           objMgmt.errorT(loc, method, "Error registering object {0}.", new Object[] {o});

      }

      loc.exiting();

   }  // method announce

}  // class Node

 

To output all the trace and log messages presented in the example above, you have to implement the following severity setting:

loc.setEffectiveSeverity(Severity.PATH);

objMgmt.setEffectiveSeverity(Severity.ERROR);

 

conLog = new ConsoleLog();

loc.addLog(conLog);

 

Output

The category objMgmt outputs two messages simultaneously – a log and a trace message.These two have the same message ID for cross-referencing each other. This makes the analysis more comfortable.

The configuration can a prior be defined in the initialization stage and can be effective to this local scope. For more information, see Typical Practice for a Better Style, Hierarchical Severity Inheritance, and Hierarchical Destination Inheritance.

If the location has a stricter severity setting, for example default Severity.NONE, the trace output will be suppressed, including the one from the category. That is, that output line will not produce two messages simultaneously, but only the log message.

Additional Configuration

More advanced configuration, regarding the correlated category and location source objects, is possible.

Example

Assume some extreme situations in the /Objects/Management category, that is, messages with severity FATAL. Several source code locations (com.sapmarkets.xxx.a, com.sapmarkets.xxx.b, and so on) can result in a fatal condition in this logical area. However, for this extreme situation you are only interested in, for example, com.sapmarkets.xxx.a, and would like to generate more output messages. This should include all messages with severity INFO or above related with this location only, while maintaining FATAL for the rest.

Having a tight severity control initially and then relaxing it for particular areas in terms to produce more output for analysis is essential. For more information about how to achieve this using the relative severities, see Relative Severities.

 

End of Content Area