Qore Logger Module Reference 1.0
Loading...
Searching...
No Matches
Logger::LoggerAppenderFileRotate Class Reference

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

#include <Logger.qm.dox.h>

Inheritance diagram for Logger::LoggerAppenderFileRotate:
[legend]

Public Member Methods

 constructor (*string name, LoggerLayout layout, string filename, int count=DEFAULT_ROTATION_COUNT, string archive=DEFAULT_ARCHIVE_PATTERN, *string encoding)
 Creates the object.
 
string getArchiveFileName (int idx)
 Returns the archive filename.
 
int getCount ()
 Returns max.number of files in chain.
 
 processEventImpl (int type, auto params)
 Implements filename rotation; handles the open and rotate events directly.
 
- Public Member Methods inherited from Logger::AbstractLoggerAppenderFileRotate
abstract int getCount ()
 Abstract method to get count of rotation objects.
 
 reopen ()
 Pushes a reopen event.
 

Public Attributes

const DEFAULT_ARCHIVE_PATTERN = "%p%f.%i"
 default archive pattern
 
- Public Attributes inherited from Logger::AbstractLoggerAppenderFileRotate
const DEFAULT_ROTATION_COUNT = 10
 default value for rotation chain
 
const EVENT_REOPEN = 10002
 reopen event
 
const EVENT_ROTATE = 10001
 rotate event
 

Private Member Methods

*string resolveField (auto data, string key, *string option)
 Returns a string for a format field for a pattern-based filename.
 

Detailed Description

Implements appender writing to a file with file rotation support.

The events will be logged to a file until rotation occurs. At that moment the current file is closed, archive chain is moved, new file is created and logging continues there.

Member Function Documentation

◆ constructor()

Logger::LoggerAppenderFileRotate::constructor ( *string  name,
LoggerLayout  layout,
string  filename,
int  count = DEFAULT_ROTATION_COUNT,
string  archive = DEFAULT_ARCHIVE_PATTERN,
*string  encoding 
)

Creates the object.

Parameters
namethe name of the appender
layoutthe layout for the appender
filenamewith pattern support; see below for more information
countnumber of files in rotation chain, if count is <=0 then no ratation is performed
archivepattern to evaluate archive filename; see below for more information
encodingthe encoding of the output file

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 "/"</td> </tr> <tr> <td>\c %%c</td> <td>Used to output the appender name</td> </tr> <tr> <td>\c %%C</td> <td>Used to output the appender class name</td> </tr> <tr> <td>\c %%E</td> <td>Used to output the environment variable with name given by option, e.g. \c "E{HOME}"</td> </tr> <tr> <td>\c %%</td> <td>The literal percent sign. \c "%%" will print a \c "%" sign</td> </tr> </table> The following table explains the characters used in @ref Qore::Logger::LoggerPattern "LoggerPattern" for archive parameter only <table> <tr> <td class="qore"><b>Conversion character</b></td> <td class="qore"><b>Meaning</b></td> </tr> <tr> <td>\c %%P</td> <td>Used to output the current logging path with filename</td> </tr> <tr> <td>\c %%p</td> <td>Used to output the current logging path</td> </tr> <tr> <td>\c %%f</td> <td>Used to output the current logging filename</td> </tr> <tr> <td>\c %%i</td> <td>Used to output the current file index from 1 to count. option may specify @ref Qore::sprintf() "sprintf()"() format, e.g. \c "%.3d"</td> </tr> <tr> <td>\c %%n</td> <td>Used to output the rotation count. Option may specify @ref Qore::sprintf() "sprintf()"() format, e.g. \c "%.3d"</td> </tr> </table> For example, the archive pattern \c "pf.i" rotates log file \c "/var/run/log/MyLogger.log" to: \c "/var/run/log/MyLogger.log.1" \c "/var/run/log/MyLogger.log.2" \c "/var/run/log/MyLogger.log.3".

◆ getArchiveFileName()

string Logger::LoggerAppenderFileRotate::getArchiveFileName ( int  idx)

Returns the archive filename.

Parameters
idxthe index of file (1..count)

◆ processEventImpl()

Logger::LoggerAppenderFileRotate::processEventImpl ( int  type,
auto  params 
)

Implements filename rotation; handles the open and rotate events directly.

All other events are handled by subclasses

Parameters
typethe event type
paramsevent parameters

◆ resolveField()

*string Logger::LoggerAppenderFileRotate::resolveField ( auto  data,
string  key,
*string  option 
)
private

Returns a string for a format field for a pattern-based filename.

Parameters
datainput context reference data
keythe format character
optionthe format option value, if any
Returns
the formatted string