
The SAP Logging API offers high quality support for common practices in logging:
It generates trace and log messages.
APIs are available to combine these two types of messages together for advanced analysis. You can find these APIs in the SAP NetWeaver Developer Studio help.
Other available advanced features are covered in later sections.
Log controllers are Java objects that manage the writing of log and trace messages. Two types of log controllers are available:
Category - generates log messages.
For example: " /System/Database ", " /System/Security ".
Location - generates trace messages.
For example: " com.sap.tc ", " com.sap.tc.logging ".
More information: Appendix B: Classes Hierarchy .
Common Logging Methods
With the Location or Category defined, you are ready to insert output methods in your code to produce messages whenever necessary. A severity level is assigned to each call.
There are a number of methods available to write messages with different severity. They can be separated in two groups, which are shown below. These methods produce messages with the respective severity incorporated in the method name.
More information: Appendix A: Severity Levels .
The first group has intuitive name with severity level indicated:
|
Common output API with severity indicated |
|---|
|
fatalT(string) |
|
errorT(string) |
|
warningT(string) |
|
infoT(string) |
|
pathT(string) |
|
debugT(string) |
The second group also has intuitive names, but without explicit severity level shown in their names. The table below shows the ones that are commonly used:
|
Common output API without severity indicated |
Description |
|---|---|
|
entering() |
Denotes a method entry with level Severity.Path . Always used together with exiting() . |
|
exiting() |
Denotes a method exit with level Severity.Path . Always used together with entering() . |
|
throwing(Throwable the_exception) |
Outputs the exception content with level Severity.Warning . |
|
assertion(Boolean the_assertion, String the_message): |
Verifies your assertion. It throws a Severity.Error message when the condition is false. |
These methods are overloaded with different arguments to enhance flexibility.
We recommend that you provide more options for different requirements, rather than to provide inadequate APIs.
More information: Enable Output Messages .
Overall Logic
General procedures:
Identify the source area you want to produce trace/log output.
Insert log messages.
Set relevant severities for the log messages.
Run the application.
The message is to be produced and sent to the destination only when the severity of the message is equal to or higher than the log controller's.
The example below corresponds to the steps mentioned above.
Source area - a class fooClass under an arbitrary package com.sapmarkets.fooPackage .
Insert an informational text at the first line of a method, that is, fooMethod() indicating the entry point to this method.
Set log message severity level higher than or equal to INFO.
The message text is written to the file with standard format as shown below:
|
May 3, 2007 6:54:18 PM com.sapmarkets.fooPackage.FooClass.fooMethod[main] Info: Method is successfully done |
This corresponds to:
|
Date and timestamp Full info method name [thread name] Severity: INFO |
More Information