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 some semantics are clearly stated in the Javadoc API under the PropertiesConfigurator class. 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

 

The attributes are in bold to distinguish them from the arbitrary <location>, which is also delimited by a period ‘.’.

This is equivalent to the following, where the configuration code is highlighted:

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 even redirect the messages into another destination (or destinations).

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, such as assigning two output destinations for the location, or replacing the default configuration with your own configuration on the log and/or on the formatter (such as assigning an XMLFormatter to a ConsoleLog instead of using the default TraceFormatter).

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 manipulate the 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.

Configuration coding:

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

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