Show TOC Start of Content Area

Background documentation Overview  Locate the document in its SAP Library structure

Use

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 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".

For more information, see 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.

For more information, see Appendix A: Severity Levels.

The first group has intuitive name with severity level indicated:

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

Verifies your assertion. It throws a Severity.Error message when the condition is false.

This graphic is explained in the accompanying text

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.

For more information, see Enable Output Messages.

Overall Logic

General procedures:

...

       1.      Identify the log controller where you want to produce trace/log output.

       2.      Assign a severity level to the source.

       3.      Specify an output destination.

       4.      Insert messages with corresponding severity level.

       5.      Run the application.

Note

The message is be produced and sent to the destination only when the severity of the message is equal to or higher than the log controller’s.

Main Tasks

From a developer’s point of view the focus is on the steps 1 and 4 defined above. The other steps are more or less determined and configured by the administrators. This concept shows the task as a complex one – enabling logs by developers, and program execution by administrators.

Example

...

Note

The example below corresponds to the steps mentioned above.

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

       2.      Severity of the log controller (source area) – DEBUG.

Allow messages with severity DEBUG level or above to be printed.

       3.      Destination – a file.

       4.      Insert an informational text at the very first line of a method, that is, a fooMethod()indicating the entry point to this method, with severity PATH (it is higher than DEBUG).

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]  Path: Entering method

This corresponds to:

Date and timestamp           Full path method name [thread name]  Severity: Message

For more information, see Simple Example Flow.

 

End of Content Area