Qore Logger Module Reference 0.4
Loading...
Searching...
No Matches
Logger::LoggerLayoutPattern Class Reference

Implements the formatting of LoggerEvent objects with a pattern. More...

#include <Logger.qm.dox.h>

Inheritance diagram for Logger::LoggerLayoutPattern:
[legend]

Public Member Methods

 constructor (string pattern=DEFAULT_PATTERN)
 Creates the object. More...
 
string format (LoggerEvent event)
 Formats an event record. More...
 
abstract string format (LoggerEvent event)
 Format event record.
 
- Public Member Methods inherited from Logger::LoggerPattern
 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...
 

Static Public Member Methods

static string getLineDelimiter ()
 Returns the line delimiter used on the current OS.
 

Public Attributes

const DEFAULT_DATE_FORMAT = "YYYY-MM-DD HH:mm:SS.u"
 default date format
 
const DEFAULT_PATTERN = "%r [%t] %p %c - %m%n"
 default layout pattern
 
const HostName = gethostname()
 This hostname.
 
- Public Attributes inherited from Logger::LoggerPattern
const ESCAPE_CHAR = "%"
 format escape character
 

Private Member Methods

*string resolveField (auto event, string key, *string option)
 Returns the value corresponding to a particular key. More...
 
abstract *string resolveField (auto data, string key, *string option)
 Returns a formatted string for an input pattern. More...
 

Additional Inherited Members

- Private Attributes inherited from Logger::LoggerPattern
list< auto > parsedPattern
 parsed pattern; list elements may be strings or hashes
 

Detailed Description

Implements the formatting of LoggerEvent objects with a pattern.

The LoggerLayoutPattern lets the user specify the output format according to conversion patterns similar to the sprintf()() function.

The following table explains the characters used in LoggerPattern and all other characters that you can use in your custom pattern:

Conversion character Meaning
%c Used to output the category of the logging event, i.e. logger name
%C Used to output the class name of the caller issuing the logging request, i.e. logger class name
%d Used to output the date of the logging event using format_date(). Option may specify date format, e.g. "%d{DD.MM.YYYY HH:mm:SS}"
%E Used to output the environment variable with name given by option, e.g. "%E{HOME}"
%F Used to output the file name where the logging request was issued
%h Used to output the hostname where the logging event was generated
%l Used to output location information of the caller which generated the logging event, i.e. "file:line [function()]"
%L Used to output the line number from where the logging request was issued, option may specify sprintf()() format, e.g. "%.3d"
%m Used to output the application supplied message associated with the logging event
%M Used to output the method name where the logging request was issued
%n Outputs the platform dependent line separator character or characters
%p Used to output the priority of the logging event
%P Used to output the PID where the logging event was generated
%r Used to output the number of milliseconds elapsed from the construction of the layout until the creation of the logging event, option may specify sprintf()() format, e.g. "%.3d"
%t Used to output the thread id that generated the logging event, option may specify sprintf()() format, e.g. "%.3d"
%u Used to output logging event unique id, option may specify sprintf()() format, e.g. "%.3d"
%x Used to output exception string using Util::get_exception_string()
%% The literal percent sign. "%%" will print a "%" sign

For example, the LoggerLayoutPattern with the conversion pattern "%r [%t] %-5p %c - %m%n" will output something like:

    176 [23] INFO  MyLogger - New record created

Member Function Documentation

◆ constructor()

Logger::LoggerLayoutPattern::constructor ( string  pattern = DEFAULT_PATTERN)

Creates the object.

Parameters
patternthe logger layout pattern

◆ format()

string Logger::LoggerLayoutPattern::format ( LoggerEvent  event)
virtual

Formats an event record.

Parameters
eventthe event to format
Returns
a formatted string for the event

Implements Logger::LoggerLayout.

◆ resolveField()

*string Logger::LoggerLayoutPattern::resolveField ( auto  event,
string  key,
*string  option 
)
privatevirtual

Returns the value corresponding to a particular key.

Parameters
event(LoggerEvent)
keythe single-character formatting code
optionoptional supporting information for key

Implements Logger::LoggerPattern.