Loading...
Searching...
No Matches
Logger::LoggerAppenderFileArchive Class Reference

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

Inheritance diagram for Logger::LoggerAppenderFileArchive:
[legend]

## Public Member Functions

string | archive ()
| Posts an archive event.
| constructor (*string name, LoggerLayout layout, string filename, string archive=DEFAULT_ARCHIVE_PATTERN, *string encoding)
| Creates the object.
string | getArchiveFileName ()
| Returns the archive filename.
| processEventImpl (int type, auto params)
| Implements archiving, handles the archive event directly, passes all other events to the subclass for handling.
Public Member Functions inherited from Logger::LoggerAppenderFile
| constructor (*string name, LoggerLayout layout, string filename, *string encoding)
| Creates the object.
File | getFile ()
| Returns the file object for the appender.
string | getFileName ()
| Returns the current filename.
| processEventImpl (int type, auto params)
| Processes open, close, and log events with the file and ignores all other events.
Public Member Functions inherited from Logger::LoggerAppenderWithLayout
| constructor (*string name, LoggerLayout layout)
| Creates the object.
LoggerLayout | getLayout ()
| Returns the layout for the appender.
| setLayout (LoggerLayout layout)
| Assigns a layout to the appender.
Public Member Functions inherited from Logger::LoggerAppender
| addFilter (LoggerFilter filter, bool top=False)
| Adds a filter to the chain.
| close ()
| Releases any resources allocated by the appender and closes it.
| constructor (*string name)
| Creates the object.
list< LoggerFilter > | getFilters ()
| Returns the filter chain as a list.
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.
bool | post (LoggerEvent event)
| Posts the given event to the output queue.
| processEvent (int type, auto params)
| Processes an event to the physical target.
abstract | processEventImpl (int type, auto params)
| Processes the event to the physical target.
| removeAllFilters ()
| Clears the filter chain by removing all filters.
| removeFilter (LoggerFilter filter)
| Removes the given filter from the filter chain.
| setQueue (*LoggerAppenderQueue queue)
| Sets the appender queue.

## 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::LoggerAppenderFile
const | EVENT_REOPEN = 1001
| reopen 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

## Protected Member Functions

*object | ensureAtomicOperations (int type)
| Returns an object that can be used to ensure atomic operations for appender operations.
*string | resolveField (auto data, string key, *string option)
| Returns a string for a format field for a pattern-based filename or archive file name.
Protected Member Functions inherited from Logger::LoggerAppenderFile
*object | ensureAtomicOperations (int type)
| Returns an object that can be used to ensure atomic operations for appender operations.
Protected Member Functions inherited from Logger::LoggerAppenderWithLayout
auto | serializeImpl (LoggerEvent event)
| Returns the value formatted using the layout pattern.
Protected Member Functions inherited from Logger::LoggerAppender
*object | ensureAtomicOperations (int type)
| Returns an object that can be used to ensure atomic operations for appender operations.
RWLock | lock ()
| The lock to ensure proper serialization with concurrent access.
bool | pushEvent (int type, auto params)
| Pushes the given event on the queue or calls processEvent() in case of synchronous processing.
abstract auto | serializeImpl (LoggerEvent event)
| Serializes the given event to put in the queue or write to the target device.
abstract *string | resolveField (auto data, string key, *string option)
| Returns a formatted string for an input pattern.
| constructor (string pattern)
| Creates the object.
string | format (auto data)
| Formats the event record with the current pattern.
string | getPattern ()
| Returns the current pattern.
| setPattern (string value)
| Sets the new pattern.

## Additional Inherited Members

Protected Attributes inherited from Logger::LoggerPattern
list< auto > | parsedPattern
| parsed pattern; list elements may be strings or hashes
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-ERROR | if target file name is not correct or target file already exists

## constructor()

Logger::LoggerAppenderFileArchive::constructor | ( | *string | name,
|  | LoggerLayout | layout,
|  | string | filename,
|  | string | archive = `DEFAULT_ARCHIVE_PATTERN`,
|  | *string | encoding
| ) |  |

Creates the object.

Parameters

  name | the name of the appender
  layout | the layout for the appender
  filename | with pattern support; see below for more information
  archive | pattern to evaluate archive filename; see below for more information
  encoding | the 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 "/"</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 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 %%d</td> <td>Used to output the date of the logging event using @ref Qore::format_date() "format_date()". Option may specify date \</td> </tr> </table> format, e.g. \c "d{DD.MM.YYYY HH:mm:SS}", default value is \c "YYYYMMDDHHmmSS" | For example, the archive pattern \c "p/archive/d/f" archives log file \c "/var/run/log/MyLogger.log" to: \c "/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

  type | the event code
  params | event parameters

Reimplemented from Logger::LoggerAppenderFile.

## resolveField()

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

protectedvirtual

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

Parameters

  data | if NOTHING, then this argument specifies the logging filename, otherwise is specifies the archive pattern
  key | the format character
  option | the format option value, if any

Returns
  the formatted string

Implements Logger::LoggerPattern.