
There are two main steps in enabling logging for your application:
Identify a source code area (for example, a class Node ) and represent it with a Location object:
Location loc = Location.getLocation("<package>.Node");
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:
com.sap.fooPackage;
com.sap.tc.logging.*;
Node {
Location loc =
Location.getLocation("com.sap.fooPackage.Node");
announce(Object o) {
String method = "announce(java.lang.Object)";
loc.entering(method);
{
// do something...
loc.debugT(method, "Connecting to …");
}
(Exception e) {
loc.fatalT(
method,
"Error processing object {0}",
Object[] { o });
}
loc.exiting();
}
}
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 |