Show TOC Start of Content Area

This graphic is explained in the accompanying text Syntax and Semantics of the Properties File  Locate the document in its SAP Library structure

The properties file has a key-value pair format. This is similar to transforming your configuration API into a list of commands of key-value-pair properties.

The syntax rule and semantics are clearly stated in the Javadoc API under the PropertiesConfiguratorclass. Therefore, this section concentrates only on providing explanations and examples.

The simplest form of the properties file is:

   <location>.attribute   =  value

   <category>.attribute   =  value

 

####Location "com.sapmarkets.foo"

com.sapmarkets.foo.severity     = WARNING

#### Now, assigning the log to the Location

com.sapmarkets.foo.logs         = ConsoleLog

 

This is equivalent to the following:

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

_loc.setEffectiveSeverity(Severity.WARNING);

_loc.removeLogs();   //clean up existing attachments

               //remember log assignment is additive?

_loc.addLog(new ConsoleLog());

_loc.fatalT(………………………..);_loc.infoT(………………………….);

 

With the use of the properties file, you can adjust the level of severity to control the amount of output, or redirect the messages into another destination.

Notice the following sample values used in the example above:

      Attributes of a LogController: severity, logs

      The value of the severity: WARNING (constant value of class the Severity). Note that the syntax of the severity value is case-sensitive.

      The value of the log: ConsoleLog (java class name of the ConsoleLog) Note that the syntax of the log value is case-sensitive.

It is not sufficient to use the ConsoleLog classname directly in case you need to do more configurations (for example, assigning two output destinations, replacing the default configuration with your own). You have to use an identifier (variable) to support these configurations. Denote the type of object, followed by the variable ID in square bracket. The two main types are:

      log[<id>]

      formatter[<id>]

You can then make configuration of the log or formatter object with its respective attributes, before really using it. For more information about the possible semantics, see Summary Highlights.

The example below presents an original configuration coding and its transformation to the properties file:

Syntax

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

_loc.setEffectiveSeverity(Severity.WARNING);

TraceFormatter _trFormatter = new TraceFormatter("% s : % - 30l[% t] : % m");

loc.addLog(new ConsoleLog(_trFormatter));

loc.addLog(new FileLog("C:\\temp\\myTrace.txt", _trFormatter));

_loc.fatalT(………………………..);

_loc.infoT(………………………….);

 

The properties file syntax is:

com.sapmarkets.foo.severity       = WARNING

#### Set up a FileLog, for storing trace, with <id>: ‘File’

log[File]            = FileLog

log[File].pattern          = C:\\temp\\myTrace.txt

log[File].formatter        = formatter[TraceNoDate]

#### Set up a ConsoleLog, with <id>: ‘Console’

log[Console]            = ConsoleLog

log[Console].formatter     = formatter[TraceNoDate]

#### Set up a TraceFormatter, with <id>: ‘TraceNoDate’

#### and its pattern starts with the Severity level, and consists no date/timestamp

formatter[TraceNoDate]     = TraceFormatter

formatter[TraceNoDate].pattern   = %s: %-30l [%t]: %m

 

com.sapmarkets.foo.logs       = log[Console], log[File]

 

Note

Using a ‘,’ makes multiple entries possible.

End of Content Area