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 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 |
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(………………………….); |
Bare in mind, that using Location.getLocation with one parameter is deprecated.
Use this method with two parameters.
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 class name directly, in case you need to do more configurations, with your own configuration on the log and/or on the formatter. For example, to assign two output destinations for the location, or replace the default configuration.
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. More information: 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 =
com.sapmarkets.foo.logs = log[Console], log[File] |
Using a ‘,’ makes multiple entries possible.