Qore logger_bin Module 2.1.1
Loading...
Searching...
No Matches
Qore::Logger::LoggerPattern Class Reference

This class implements LoggerPattern functionality. More...

#include <QC_LoggerPattern.dox.h>

Inheritance diagram for Qore::Logger::LoggerPattern:
Qore::Logger::LoggerLayoutPattern

Public Member Methods

 constructor (string pattern)
 Creates the object.
 
string format (auto data)
 Formats the event record with the current pattern.
 
list< auto > getParsedPattern ()
 Returns the parsed pattern list.
 
string getPattern ()
 Returns the current pattern.
 
 setPattern (string pattern)
 Sets the new pattern.
 

Private Member Methods

abstract *string resolveField (auto data, string key, *string option)
 Returns a formatted string for an input pattern.
 

Detailed Description

This class implements LoggerPattern functionality.

The pattern defines fields to be substituted with real values

The pattern format is:

%[<modifiers>] <word> [{<option>}]
modifiers := [0-9.-]*
word := [a-zA-Z]+
option := [^}]*

When a word (i.e. longer than one char) key without curly brackets is not found then in the next step is resolved its first char, e.g. "%parchive" the first step tries to resolve "parchive" key and if not resolved the second step "p" key. To parse in key if single step delimit a word from the next character, use curly brackets, i.e. empty option, e.g. "%p{}archive". If a key is not resolved then exception is raised.

The following table covers various modifiers and scenarios:

Format modifier Left justify Minimum width Maximum width Comment
%20c false 20 none Left pad with spaces if the category name is less than 20 characters long
%-20c true 20 none Right pad with spaces if the category name is less than 20 characters long
%.30c NA none 30 Truncate from the beginning if the category name is longer than 30 characters
%20.30c false 20 30 Left pad with spaces if the category name is shorter than 20 characters. However, if the category name is longer than 30 characters, then truncate from the beginning
%-20.30c true 20 30 Right pad with spaces if the category name is shorter than 20 characters. However, if the category name is longer than 30 characters, then truncate from the beginning
Since
Qore 2.0

Member Function Documentation

◆ constructor()

Qore::Logger::LoggerPattern::constructor ( string  pattern)

Creates the object.

Example:
LoggerPattern pattern(pat);

◆ format()

string Qore::Logger::LoggerPattern::format ( auto  data)

Formats the event record with the current pattern.

Parameters
datais passed to resolveField()
Exceptions
LOGGER-ERRORwhen a key is not resolved

◆ resolveField()

abstract *string Qore::Logger::LoggerPattern::resolveField ( auto  data,
string  key,
*string  option 
)
private

Returns a formatted string for an input pattern.

Parameters
datainput context reference data
keythe format character
optionthe format option value, if any
Returns
the formatted string or nothing if the key is not resolved

◆ setPattern()

Qore::Logger::LoggerPattern::setPattern ( string  pattern)

Sets the new pattern.

Parameters
patternthe logger pattern
Exceptions
LOGGER-ERRORwhen pattern is invalid

The documentation for this class was generated from the following file: