Show TOC

Relations Between Category and LocationLocate this document in the navigation 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 area and the source code location that generates the problem is highly desired.

Example

For example, an error occurs when closing the database. The actual location of the source code (from which class, which method, with what arguments) is also reported.

More information: Message Output with Severity .

Example

This example only shows the attachment of a location to a category but this is relevant for the opposite case, too.

Note

SAP Logging API supports the assignment of a category to a location and also the other way round, but not among the same type. It is legitimate to associate more than one category to a location at each logging, but only one location for one category.


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 new object {0}.", 
 Object[] {o});
      }
      loc.exiting();
   }  // method announce
}  // class Node
         

Output

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

There is a possibility for the configuration to already be defined in the initialization stage and to be effective to this local scope through the hierarchical inheritance logic.

More information:

Hierarchical Destination Inheritance .

Additional Configuration

It is possible to have more advanced configuration, regarding the correlated category and location source objects.

Example

Consider, for example, 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 interested in one of them, for example com.sapmarkets.xxx.a . Therefore, you would like to generate more output messages, including all with severity INFO or above, related with this location only. For the rest, use the severity FATAL .