Show TOC Start of Content Area

This graphic is explained in the accompanying text Enabling Logging for Applications  Locate the document in its SAP Library structure

There are mainly four steps in enabling logging for your application.

...

       1.      Identify a source code area (for example, a class Node) and represent it with a Location object:

Location loc = Location.getLocation("<package>.Node"); 

       2.      Assign a severity level to the source:

loc.setSeverity(Severity.WARNING);   //default: Severity.NONE

       3.      Specify an output destination:

loc.addLog(new ConsoleLog());        //with default formatter: TraceFormatter

       4.      Generate a trace message with specified severity:

loc.entering(methodname);

loc.debugT(methodname, message);

loc.fatalT(methodname, message);

It is a legitimate deduction that more than 90% of your development time is spent on step 1 and 4. Eventually, step 2 and 3 can be mainly configured externally so that users can control the output with no need to modify the source code and recompile again.

A basic sample code shows step 1 and step 4:

This graphic is explained in the accompanying text

package com.sap.fooPackage;

import com.sap.tc.logging.*;

public class Node {

   private static final Location loc =

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

   public void announce(Object o) {

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

      loc.entering(method);

      try {

         // do something...

         loc.debugT(method, "Connecting to …");

      } catch (Exception e) {

         loc.fatalT(

            method,

            "Error processing object {0}",

            new Object[] { o });

      }

      loc.exiting();

   }

}

Steps 2 and 3 are not shown at this point, so you assume that the severity level assigned to this is Severity.ALL (accept all severity levels and output everything) and the output is displayed to a ConsoleLog(terminal).

The output, formatted with TraceFormatter (default formatter for ConsoleLog), looks like this:

May 3, 2003 6:54:18 PM com.sap.fooPackage.Node.announce [main]  Path: Entering method

May 3, 2003 6:54:18 PM com.sap.fooPackage.Node.announce [main]  Debug: Connecting to ….

May 3, 2003 6:54:18 PM com.sap.fooPackage.Node.announce [main]  Path: Exiting method

 

For more information about each of the defined steps, see:

Identify the Output Source: Location or Category

Assign a Severity to a Source

Specify an Output Destination

Enable Output Messages

 

End of Content Area