Show TOC Start of Content Area

Background documentation Overview  Locate the document in its SAP Library structure

The SAP Logging API offers high quality support for common practices in logging:

      It generates trace and log messages.

      APIs are available that combine these two types of messages together for advanced analysis. You can find these APIs in the SAP NetWeaver Developer Studio help.

      Other advanced features are available that will be covered in later sections.

Basic Classes

Log Controller is the Java class that represents the logging source area. In general, you deal with its two subclasses directly:

      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 – Group 1

Common output API with severity indicated

fatalT(string the_message)

errorT(string the_message)

warningT(string the_message)

infoT(string the_message)

pathT(string the_message)

debugT(string the_message)

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 – Group 2

Common output API (mostly for program flow)

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):

A trace method to verify your assertion. It throws a Severity.Error message when the condition is false.

Recommendation

It may first appear that there is a large number of methods, but they are overloaded methods with different arguments to enhance flexibility. It is better for you to provide more options for different requirements, rather than to provide inadequate APIs.

More information: Enable Output Messages.

Overall Logic

General procedures:

...

       1.      Identify the source area you want to produce trace/log output.

       2.      Insert log messages.

       3.      Set relevant severities for the log messages.

       4.      Run the program.

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.

Example

A Sample Idea and Output

Note

The example below corresponds to the steps mentioned above.

       1.      Source area – a class fooClass under an arbitrary package com.sapmarkets.fooPackage.

       2.      Insert an informational text at the very first line of a method, that is, a fooMethod() indicating the entry point to this method.

       3.      Set log message severity level higher than or equal to INFO.

The message text is written to the file with a standard format as shown below:

May 3, 2001 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: Message

 

More information: Simple Example Flow.

 

 

End of Content Area