Show TOC Start of Content Area

Procedure documentation Specify an Output Destination Locate the document in its SAP Library structure

Use

Use the output destination to print out log messages. You must assign a log destination to a location or category, otherwise nothing will be printed, even though you set the severity and inserted the output methods correctly. You can assign a log destination to a source using the loc.addLog(<log1>);.

The following log destination types are available:

·        ConsoleLog – used for printing to a terminal.

·        FileLog – used for writing messages to files.

Multiple Destinations

You can assign multiple logs to a single source. Message generated from a source will be sent to both of them simultaneously. The example below illustrates how you can output messages to both a console and a file:

This graphic is explained in the accompanying text

loc.addLog(new ConsoleLog());

loc.addLog(new FileLog(“C:\\temp\\testOutput.log”);  // filepath has to be valid

 

Procedure

...

       1.      Create a log destination.

Looking at the SAP Logging API you can see that the constructors are overloaded and you can specify certain options for the logs, although this tutorial only shows the most basic one (using minimal parameters for simplicity). The default settings are:

                            a.      ConsoleLog is using a TraceFormatter by default.

                            b.      FileLog is using a ListFormatter and the output file will not be a rolling file type, but one single output file, increasing in size when more and more messages are appended to it. For more information about the configurations that can be specified for a FileLog, see Output File.

This graphic is explained in the accompanying text

If you want to switch to an XMLFormatter of a FileLog, you can call:

loc.addLog(new FileLog(“C:\temp\testOutput.log”, new XMLFormatter());

You can also use an existing log:

<filelog>.setFormatter(new XMLFormatter());

 

       2.      Attach the log destination.

In addition to the addLog described above, there are two more APIs for assigning a log destination to a location or category – addPrivateLog and addLocalLog, because there are actually three forms of log assignments. They behave differently in terms of inheritance by children of a location or category source. In short, these three are mutually exclusive, and the addLog example shown above is straightforward for beginners. It completely supports forced inheritance to children and message output. For more information, see Hierarchical Destination Inheritance and Log Assignment.

 

See also:

Log (Destination)

End of Content Area