| Qore Logger Module Reference 0.2

Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
Logger::LoggerPattern Class Referenceabstract

Implements pattern parsing and substitution. More...

Inheritance diagram for Logger::LoggerPattern:
[legend]

## Public Member Functions
| 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

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

## Protected Attributes
list< auto > | parsedPattern
| parsed pattern; list elements may be strings or hashes

## Private 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

  pattern | the logger pattern

Exceptions

  LOGGER-ERROR | when pattern is invalid

## ◆ format()

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

Formats the event record with the current pattern.

Parameters

  data | is passed to resolveField()

Exceptions

  LOGGER-ERROR | when a key is not resolved

## ◆ resolveField()

abstract *string Logger::LoggerPattern::resolveField | ( | auto | data,
|  | string | key,
|  | *string | option
| ) |  |
| protected pure virtual

Returns a formatted string for an input pattern.

Parameters

  data | input context reference data
  key | the format character
  option | the format option value, if any

Returns
  the formatted string or nothing if the key is not resolved

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

## ◆ setPattern()

Logger::LoggerPattern::setPattern | ( | string | value | ) |

Sets the new pattern.

Parameters

  value | the logger pattern

Exceptions

  LOGGER-ERROR | when pattern is invalid