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.

This section concentrates on providing explanations and examples only.

Features

Default configuration

  • It uses file set of five files. Each file has maximum size of 10485760 bytes.

    Log files uses TraceFormatter ("%24d %s: %M %m"). Trace files uses ListFormater.

  • If you do not need to add trace or log file set, you can use null ('0').

  • By default, the severity level for category is WARNING, and for locations – is ERROR.

    If you need to use a different severity level, you can use the setEffectiveSeverity method after the defaultConfiguration method line.

Customer configuration

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

  • The syntax of the severity value is case-sensitive.

  • The syntax of the log value is case-sensitive.

  • You have to use an identifier (variable) to support your configurations. Denote the type of object, followed by the variable ID in square bracket.

    The two main types are: log[<id>] and formatter[<id>].

  • Using a ',' makes multiple entries possible.

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

  • You can then manipulate the configuration of the log or formatter object with its respective attributes.

    More information: Summary Highlights.

Example

Properties File Structure

The simplest form of the properties file is:

<location>.attribute = value

<category>.attribute = value

Syntax Syntax

  1.    // The location is "configtool"
    configtool.severity = WARNING
       // Now, assign the log to the location
    trace = FileLog
    trace.pattern = ./configtool.trc
    trace.limit = 10485760
    trace.cnt = 5 
    trace.severity = ALL
    configtool.logs = trace
    
End of the code.
Configuration of a Log Controller

You can do the same configuration using the code example below:

Syntax Syntax

  1. Location location = Location.getLocation("configtool", DC_NAME, CSN_COMPONENT);
    location.setEffectiveSeverity(Severity.WARNING);
       // clean up existing attachments
    location.removeLogs();
       // remember you should assign log to the log controller (location or category)
    Log trace = new FileLog( traceFileName, FILE_SET_LIMIT, FILE_SET_COUNT);
    trace.setEffectiveSeverity( Severity.ALL );
    location.addLog(trace);
    
End of the code.

Note Note

The type of the parameters FILE_SET_LIMIT and FILE_SET_COUNT is final Int.

Their values are: FILE_SET_LIMIT = 10485760; and FILE_SET_COUNT = 5;

End of the note.
Default Configuration

The default configuration does the same as the example above. The difference is that the parameters FILE_SET_LIMIT and FILE_SET_COUNT, as well as the severity level have default values.

Syntax Syntax

Location
  1. location = Location.getLocation("configtool", DC_NAME, CSN_COMPONENT);
    LoggingUtilities.defaultConfiguration(location, TRACE_FILE);
    location.setEffectiveSeverity(Severity.WARNING);
End of the code.

Syntax Syntax

Category
  1. category = Category.getCategory(Category.getRoot(), "configtool");
    LoggingUtilities.defaultConfiguration(category, LOG_FILE);
End of the code.

Syntax Syntax

Changes
  1. changes = Category.getCategory( Category.SYS_CHANGES, "configtool" );
    LoggingUtilities.defaultConfiguration(changes, LOG_FILE_CHANGES);
End of the code.

Note Note

The type of the parameters DC_NAME, CSN_COMPONENT, TRACE_FILE, LOG_FILE and LOG_FILE_CHANGES is final String.

End of the note.
Transformation to a Properties File

The following example represents real 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’
       // Its pattern starts with the Severity level, and contains 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.