Show TOC

Background documentationEnabling Logging for Applications Locate this document in the navigation structure

 

There are two main 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. Input a trace message with specified severity:

    loc.entering(methodname);

    loc.debugT(methodname, message);

    loc.fatalT(methodname, message);

A very basic sample code shows these two steps:

Syntax Syntax

  1. 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();
       }
    }
End of the code.

The output is redirected to a ConsoleLog (terminal).

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

May 3, 2007 6:54:18 PM com.sap.fooPackage.Node.announce [main] Path: Entering method May 3, 2001 6:54:18 PM com.sap.fooPackage.Node.announce [main] Debug: Connecting to …. May 3, 2001 6:54:18 PM com.sap.fooPackage.Node.announce [main] Path: Exiting method