20.4. Logger Configuration Using the Registry

[Note]Note

See Configuration Files Syntax for general information about how to write configuration files; see Registry for more information about Registry.

Logger instance can be initialized from registry using method initialize_from_registry() supposing that the registry itself has already been initialized and has read its configuration files.

20.4.1. Registry Nodes Involved Into Logger Configuration

The main node is Logger. If this node is not contained in the registry, the default settings are applied - i.e. all log messages are sent to cout. Otherwise the default settings are not considered.

If the registry contains the Logger node, it must contain also all of the following:

  • Logger/Destinations node: describes all destinations that should be registered with the Logger.

  • Logger/SelectorElements node: describes all selector elements that may be included into selectors.

  • Logger/Selectors node: describes all selectors, i.e. their elements and destinations.

20.4.2. Logger Destinations Declaration

Logger destinations declaration is contained in the Logger/Destinations node. It is a set of strings, one for each destination. All of the strings may have arbitrary name, important is the strings' contents. See the following table for the full description:

Table 20.1. Logger Destinations
String contentsMeaning
coutStandard output
cerrError output
#fileFile, filename consists of path and filename.

[Note]Note

The cout destination is registered by default. However if you load the logger configuration from the registry, cout won't be registered unless it is contained in the configuration.

Example 20.1. Logger destinations declaration example
[ Logger/Destinations ]
dest1 : string = "cout"
dest2 : string = "#net.log"
dest3 : string = "#thrash/garbage.log"

The previous lines register standard output, net.log and thrash/garbage.log files as logger destinations.

[Note]Note

For the file log destination there should not be specified an absolute path, because the string stands for only a name of a log. There might be added some other path (path to the log directory, for example) before it sometimes. This would make the path invalid if the string in the configuration was an absolute path.

20.4.3. Selector Elements Declaration

Selector elements declaration takes place in the Logger/SelectorElements node. This node should contain a set of subnodes - one for each selector element - of arbitrary names. Each of the subnodes consists of up to four variable declarations: priority, type, facility and negate. Priority, type and facility are each log message's atributes - according to them the message is being filtered.

Priority and type are strings containing a comparison sign and a keyword. Comparison sign of one of <, >, <=, >= and =; possible keywords are described in the following table (see also src/core/status/status.h):

Table 20.2. Logger Selector Attributes
SettingsPossible keywords
prioritylowest, low, normal, high, highest
typeany, debug, info, warning, error

facility contains just a name of some facility. At present, posible facilities are: any, generic, system, io, logger, network, registry, object_management, object_localization, archivation, crypto, file_system, lru_cache, synchronization, thread, data_management, time_management, test, node_database, archive_database, node_management and replication. See src/core/status/status.h for complete list.

negate is a boolean variable. If true, a log message matches the selector element if it doesn't match any of priority, type or facility constraints.

Example 20.2. Declaring two selector elements of names Element1 and Element2
[ Logger/SelectorElements/Element1 ]
priority        : string = ">= low"
type            : string = "<= warning"
facility        : string = "any"
negate          : boolean = false

[ Logger/SelectorElements/Element2 ]
priority        : string = ">= lowest"
type            : string = "= info"
facility        : string = "network"
negate          : boolean = false

20.4.4. Selectors Declaration

Each selector consists of a set of selector elements, each specifying an atomic condition, and set of destinations. All selector definitions are contained in the Logger/Selectors node; this node contains none or more subnodes (each for one selector) of arbitrary names. Each of these subnodes contains two more subnodes Elements and Destinations.

Elements subnode describes which selector elements should be included into this selector. It is a set of strings of arbitrary names - each string should contain name of one element declared under the Logger/SelectorElements node.

Destinations subnode determines all destinations the messages matching this selector will be sent to. Its items are either strings containing name of destination declared in the Logger/Destinations node or symbolic links refering to these variables.

Example 20.3. Selectors declaration

[Note]Note

Let's suppose all declarations from previous examples are valid.

[ Logger/Selectors/Selector1/Elements ]
element1        : string = "Element1"

[ Logger/Selectors/Selector1/Destinations ]
destination1    : symlink = Logger/Destinations/dest3
destination2    : string = "cout"

[ Logger/Selectors/Selector2/Elements ]
element1        : string = "Element2"

[ Logger/Selectors/Selector2/Destinations ]
destination1    : string = "#net.log"

In this example there are two selectors declared - Selector1 and Selector2. The first of includes selector element declared as Element1, the second includes Element2. The first selector directs all matching messages to #thrash/garbage.log (dest3) and to cout, the second one sends messages to #net.log.

20.4.5. Example

Example 20.4. Configuration using the registry - complex example
# Note that this file should be a part of the main massiv 
# configuration file or it should be included (directly or 
# indirectly) using the !include directive.

[ Logger ]

#################################################
# Logger destinations declaration section
##########

[ Logger/Destinations ]
dest1 : string = "cout"
dest2 : string = "#net.log"
dest3 : string = "#thrash/garbage.log"



#################################################
# Selector elements declaration section
##########

### 'Element1' declaration ###
[ Logger/SelectorElements/Element1 ]
priority        : string = ">= low"
type            : string = "<= warning"
facility        : string = "any"
negate          : boolean = false

### 'Element2' declaration ###
[ Logger/SelectorElements/Element2 ]
priority        : string = ">= lowest"
type            : string = "= info"
facility        : string = "network"
negate          : boolean = false



#################################################
# Logger selectors declaration section
##########

### 'Selector1' declaration ###
[ Logger/Selectors/Selector1/Elements ]
element1        : string = "Element1"

[ Logger/Selectors/Selector1/Destinations ]
destination1    : symlink = Logger/Destinations/dest3
destination2    : string = "cout"


### 'Selector2' declaration ###
[ Logger/Selectors/Selector2/Elements ]
element1        : string = "Element2"

[ Logger/Selectors/Selector2/Destinations ]
destination1    : string = "#net.log"