Show TOC Start of Content Area

Function documentation Typical Practice for a Better Style  Locate the document in its SAP Library structure

Use

In addition to the steps in the previous sections, a good style of logging is recommended. That means enabling logging in two major steps – initialization and individual source classes.

Higher Level versus Individual Level

Applications normally consist of different components and are deployed in a distributed environment. Typically, there has to be a common initialization routine for a component. Logging configuration, such as setting severity and assigning destination logs, can also be done at this stage.

A top-down approach is used, that is, defining a basic configuration on a higher level (component-oriented parent node). Mostly you do not need to tune the logging behavior in such details for each class. In this case, a basic configuration at the top level is good enough to get the logging started.

Component Level at Initialization

For example, a component ComX under SAP Markets may have the following package hierarchy: com.sapmarkets.comX.xxx.xxxx.xxx. During initialization, if logging is desired for monitoring important messages (with severity ERROR or above) and for displaying the results in a console, you have to use the following syntax:

This graphic is explained in the accompanying text

Location _loc = Location.getLocation("com.sapmarkets.comX");

_loc.setEffectiveSeverity(Severity.ERROR);

_loc.addLog(new ConsoleLog());

 

Class Level

In the individual class, it is recommended to have a static variable to hold the access to the location object (for better performance) and then start inserting messages:

This graphic is explained in the accompanying text

static Location _loc = Location.getLocation(<classname>.class);

_loc.infoT(… ….);

_loc.errorT(… ….);

 

      The code is better structured if use this two-level setting, which is available due to the hierarchical feature implemented in the logging framework.

For more information, see Hierarchical Severity Inheritance and Hierarchical Destination Inheritance.

      The actual logging part within each class is static. Only the configuration part of the logging behavior is dynamic, such as, output volume, output destination, output format.

For more information, see Configuration Tool.

 

End of Content Area