Show TOC

Background documentationSyntax and Semantics of the Properties File Locate this document in the navigation 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.

Example

The simplest form of the properties file is:

<location>.attribute = value

<category>.attribute = value

Syntax Syntax

  1. ####Location "com.sapmarkets.foo"
    com.sapmarkets.foo.severity = WARNING
    ####Now, assigning the log to the Location
    com.sapmarkets.foo.logs = ConsoleLog
End of the code.

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:

Syntax Syntax

  1. 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();
End of the code.

Caution Caution

Bear in mind, that using Location.getLocation with one parameter is deprecated.

Use this method with two parameters.

End of the caution.
Features

Using 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 the class 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 represents an original configuration coding and its transformation to the properties file.

Configuration coding:

Syntax Syntax

  1. 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();
End of the code.

The properties file syntax

Syntax Syntax

  1. 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]
End of the code.

Note Note

Using a ',' makes multiple entries possible.

End of the note.