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 denote where the log/trace messages to be written (printed out). You must assign a log destination to a location or category, otherwise nothing will be written, 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 writing messages to a terminal.

      FileLog – used for writing messages to a file.

Multiple Destinations

You can assign multiple logs to a single source. Message generated from a source is 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. The default settings are:

                            a.      ConsoleLog is using a TraceFormatter by default.

                            b.      FileLog is using a ListFormatter and the output file is not a rolling file type, but a single output file, increasing in size when more messages are appended to it. For more information, see Output File.

This graphic is explained in the accompanying text

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

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.

There are two more APIs for assigning a log destination to a location or category – addPrivateLog and addLocalLog. They behave differently about inheritance by children of a location or category source.

Note

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.

 

More information:

Log (Destination)

End of Content Area