Qore Logger Module Reference 0.6
Loading...
Searching...
No Matches
Logger::LoggerPattern Class Referenceabstract

Implements pattern parsing and substitution. More...

#include <Logger.qm.dox.h>

Inheritance diagram for Logger::LoggerPattern:
[legend]

Public Member Methods

 constructor (string pattern)
 Creates the object. More...
 
string format (auto data)
 Formats the event record with the current pattern. More...
 
string getPattern ()
 Returns the current pattern.
 
 setPattern (string value)
 Sets the new pattern. More...
 

Public Attributes

const ESCAPE_CHAR = "%"
 format escape character
 

Private Member Methods

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

Private Attributes

list< auto > parsedPattern
 parsed pattern; list elements may be strings or hashes
 

Private:Internal Attributes

string origPattern
 pattern
 

Detailed Description

Implements pattern parsing and substitution.

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

Member Function Documentation

◆ constructor()

Logger::LoggerPattern::constructor ( string  pattern)

Creates the object.

Parameters
patternthe logger pattern
Exceptions
LOGGER-ERRORwhen pattern is invalid

◆ format()

string 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 Logger::LoggerPattern::resolveField ( auto  data,
string  key,
*string  option 
)
privatepure virtual

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

Implemented in Logger::LoggerAppenderFileRotate, Logger::LoggerAppenderFileRing, Logger::LoggerAppenderFileArchive, and Logger::LoggerLayoutPattern.

◆ setPattern()

Logger::LoggerPattern::setPattern ( string  value)

Sets the new pattern.

Parameters
valuethe logger pattern
Exceptions
LOGGER-ERRORwhen pattern is invalid