Logger::LoggerAppender Class Referenceabstract

Implements passing LoggerEvent to target destination. More...

Inheritance diagram for Logger::LoggerAppender:
[legend]

## Public Member Functions

| 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 name)
| Creates the object. More...
list< LoggerFilter > | getFilters ()
| 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...
abstract | processEventImpl (int type, auto params)
| Processes the event to the physical target. More...
| removeAllFilters ()
| Clears the filter chain by removing all filters.
| removeFilter (LoggerFilter filter)
| Removes the given filter from the filter chain. More...
| setQueue (*LoggerAppenderQueue queue)
| Sets the appender queue. More...

## Public Attributes

const | EVENT_CLOSE = 3
| close event
const | EVENT_LOG = 2
| logging event
const | EVENT_OPEN = 1
| open event

## Protected Member Functions

bool | pushEvent (int type, auto params)
| Pushes the given event on the queue or calls processEventImpl() in case of synchronous processing. More...
abstract auto | serializeImpl (LoggerEvent event)
| Serializes the given event to put in the queue or write to the target device. More...

## Private Member Functions

RWLock | lock ()
| The lock to ensure proper serialization with concurrent access.

## Private Attributes

bool | active = False
| An inactive appender won't accept any logging request.
list< LoggerFilter > | filters
| filter chain
string | name
| Appender name.
*LoggerAppenderQueue | queue
| async queue

## Detailed Description

Implements passing LoggerEvent to target destination.

subclasses will implement e.g. logging to file, to stderr, to database etc. `LoggerAppender` supports sync and async logging.

The ability to selectively enable or disable logging requests based on level in Logger is extended in the appender via LoggerFilter, which implements filtering on any criteria.

The appender instance should be closed via close() method explicitely to stop accepting logging events which might arrive later than destructing process has started. This process cannot start by design before all events has been processed as the LoggerEvent instance holds refeence to this appender instance.

## Member Function Documentation

## addFilter()

Logger::LoggerAppender::addFilter | ( | LoggerFilter | filter,
|  | bool | top = `False`
| ) |  |

Adds a filter to the chain.

Parameters

  filter | the new filter to add
  top | if True then the filter is added at the start of the filter chain, if False (the default), the filter is added at the end of the chain

Exceptions

  LOGGER-ERROR | thrown if the filter is already in the list

## constructor()

Logger::LoggerAppender::constructor | ( | *string | name | ) |

Creates the object.

Parameters

  name | the appender name

## getFilters()

list<LoggerFilter> Logger::LoggerAppender::getFilters | ( |  | ) |

Returns the filter chain as a list.

Note that appender filter chain may be modified as internal lock is released when copy of list is returned

## open()

Logger::LoggerAppender::open | ( |  | ) |

Opens logging resources.

The appender must be opened to accept any logging events

## post()

bool Logger::LoggerAppender::post | ( | LoggerEvent | event | ) |

Posts the given event to the output queue.

Invokes filters; when the event is accepted then it is posted to the queue in case of asynchronous processing, or it is immediately logged by the processEventImpl() method in case of synchronous processing.

See also
  processEventImpl()

Parameters

  event | the event to post

Returns
  True if the event has been posted, False if not (filtered out, appender inactive, event not accepted on queue, etc)

## processEventImpl()

abstract Logger::LoggerAppender::processEventImpl | ( | int | type,
|  | auto | params
| ) |  |

pure virtual

Processes the event to the physical target.

Must be implemented by non-abstract subclasses

See also
  serializeImpl()

Parameters

  type | see `"EVENT_xxx"` constants
  params | processing parameters

Implemented in Logger::LoggerAppenderFileArchive, Logger::LoggerAppenderFileRing, Logger::LoggerAppenderFileRotate, Logger::LoggerAppenderStdErr, Logger::LoggerAppenderStdOut, Logger::LoggerAppenderFile, Logger::LoggerAppenderStream, and Logger::LoggerAppenderNull.

## pushEvent()

bool Logger::LoggerAppender::pushEvent | ( | int | type,
|  | auto | params
| ) |  |

protected

Pushes the given event on the queue or calls processEventImpl() in case of synchronous processing.

Parameters

  type | the event type
  params | parameters for the event according to the event type

Returns
  True if the event was accepted/processed, False if not

See also
  processEventImpl()

## removeFilter()

Logger::LoggerAppender::removeFilter | ( | LoggerFilter | filter | ) |

Removes the given filter from the filter chain.

Parameters

  filter | the filter to remove

## serializeImpl()

abstract auto Logger::LoggerAppender::serializeImpl | ( | LoggerEvent | event | ) |

protectedpure virtual

Serializes the given event to put in the queue or write to the target device.

The appender implementaion can define any format for serialization. The data are passed to processEventImpl() method in the `params` argument when `type` is `EVENT_LOG`.

Returns
  the serialized event

Implemented in Logger::LoggerAppenderWithLayout, and Logger::LoggerAppenderNull.

## setQueue()

Logger::LoggerAppender::setQueue | ( | *LoggerAppenderQueue | queue | ) |

Sets the appender queue.

Data are passed to target device synchronously unless queue is assigned. In this case data are queued and dedicated process will process it asynchronously

Parameters

  queue |

Exceptions

  LOGGER-ERROR | thrown if appender is opened