Qore Logger Module Reference  0.1.1
Logger::LoggerAppenderFileArchive Class Reference

Implements appender writing to a file with archive support. More...

Inheritance diagram for Logger::LoggerAppenderFileArchive:

Public Member Methods

string archive ()
 Posts an archive event. More...
 
 constructor (*string n_name, LoggerLayout n_layout, string n_filename, string n_archive=DEFAULT_ARCHIVE_PATTERN, *string n_encoding)
 Creates the object. More...
 
string getArchiveFileName ()
 Returns the archive filename. More...
 
 processEventImpl (int type, auto params)
 Implements archiving, handles the archive event directly, passes all other events to the subclass for handling. More...
 
- Public Member Methods inherited from Logger::LoggerAppenderFile
 constructor (*string n_name, LoggerLayout n_layout, string n_filename, *string n_encoding)
 Creates the object. More...
 
File getFile ()
 Returns the file object for the appender.
 
string getFileName ()
 Returns the current filename.
 
- Public Member Methods inherited from Logger::LoggerAppenderWithLayout
 constructor (*string n_name, LoggerLayout n_layout)
 Creates the object. More...
 
LoggerLayout getLayout ()
 Returns the layout for the appender.
 
 setLayout (LoggerLayout n_layout)
 Assigns a layout to the appender. More...
 
- Public Member Methods inherited from Logger::LoggerAppender
 addFilter (LoggerFilter filter, bool top=False)
 Adds a filter to the chain. More...
 
 close ()
 Releases any resources allocated by the appender and closes it.
 
 constructor (*string n_name)
 Creates the object. More...
 
list< LoggerFiltergetFilters ()
 Returns the filter chain as a list. More...
 
string getName ()
 Returns the appender name.
 
*LoggerAppenderQueue getQueue ()
 Returns async queue or NOTHING when events are processed synchronously.
 
bool isOpen ()
 Returns True if the appender is open and therefore active.
 
 open ()
 Opens logging resources. More...
 
bool post (LoggerEvent event)
 Posts the given event to the output queue. More...
 
 removeAllFilters ()
 Clears the filter chain by removing all filters.
 
 removeFilter (LoggerFilter filter)
 Removes the given filter from the filter chain. More...
 
 setQueue (*LoggerAppenderQueue n_queue)
 Sets the appender queue. More...
 

Public Attributes

const DEFAULT_ARCHIVE_PATTERN = "%p%f.%d"
 default archive pattern
 
const DEFAULT_DATE_FORMAT = "YYYYMMDDHHmmSS"
 default date format
 
const EVENT_ARCHIVE = 20
 archive event
 
- Public Attributes inherited from Logger::LoggerAppender
const EVENT_CLOSE = 3
 close event
 
const EVENT_LOG = 2
 logging event
 
const EVENT_OPEN = 1
 open event
 

Private Member Methods

*string resolveField (auto data, string key, *string option)
 Returns a string for a format field for a pattern-based filename or archive file name. More...
 
- Private Member Methods inherited from Logger::LoggerAppenderWithLayout
auto serializeImpl (LoggerEvent event)
 Returns the value formatted using the layout pattern. More...
 
- Private Member Methods inherited from Logger::LoggerAppender
bool pushEvent (int type, auto params)
 Pushes the given event on the queue or calls processEventImpl() in case of synchronous processing. More...
 
 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...
 

Additional Inherited Members

- Private Attributes inherited from Logger::LoggerPattern
list parsedPattern
 parsed pattern
 
const ESCAPE_CHAR = "%"
 format escape character
 

Detailed Description

Implements appender writing to a file with archive support.

The events will be logged to a file until archiving is triggered. At that moment the current file is closed, moved to file with name evaluated in runtime from the archive pattern set in the object, the new file is created, and logging continues to that file. The archive never overwrites any existing file.

Member Function Documentation

◆ archive()

string Logger::LoggerAppenderFileArchive::archive ( )

Posts an archive event.

rename logging file and open new one

Returns
archive file name
Exceptions
LOGGER-ERRORif target file name is not correct or target file already exists

◆ constructor()

Logger::LoggerAppenderFileArchive::constructor ( *string  n_name,
LoggerLayout  n_layout,
string  n_filename,
string  n_archive = DEFAULT_ARCHIVE_PATTERN,
*string  n_encoding 
)

Creates the object.

Parameters
n_namethe name of the appender
n_layoutthe layout for the appender
n_filenamewith pattern support; see below for more information
n_archivepattern to evaluate archive filename; see below for more information
n_encodingthe output file's encoding

The following table explains the characters used in LoggerPattern for both filename and archive parameter

Conversion character Meaning
s Used to output the OS directory separator, i.e. "\" or "/"
c Used to output the appender name
C Used to output the appender class name
E Used to output the environment variable with name given by option, e.g. "%E{HOME}"
% The literal percent sign. "%%" will print a "%" sign

The following table explains the characters used in LoggerPattern for archive parameter only

Conversion character Meaning
P Used to output the current logging path with filename
p Used to output the current logging path
f Used to output the current logging filename
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}", default value is "YYYYMMDDHHmmSS"

For example, the archive pattern "%p/archive/%d/%f" archives log file "/var/run/log/MyLogger.log" to: "/var/run/log/archive/20180120102030/MyLogger.log".

◆ getArchiveFileName()

string Logger::LoggerAppenderFileArchive::getArchiveFileName ( )

Returns the archive filename.

The pattern may contain date fields so the result may differ when executed multiple times

◆ processEventImpl()

Logger::LoggerAppenderFileArchive::processEventImpl ( int  type,
auto  params 
)
virtual

Implements archiving, handles the archive event directly, passes all other events to the subclass for handling.

Parameters
typethe event code
paramsevent parameters

Reimplemented from Logger::LoggerAppenderFile.

◆ resolveField()

*string Logger::LoggerAppenderFileArchive::resolveField ( auto  data,
string  key,
*string  option 
)
privatevirtual

Returns a string for a format field for a pattern-based filename or archive file name.

Parameters
dataif NOTHING, then this argument specifies the logging filename, otherwise is specifies the archive pattern
keythe format character
optionthe format option value, if any
Returns
the formatted string

Implements Logger::LoggerPattern.