Qore Logger Module Reference 0.6
Loading...
Searching...
No Matches
Logger::LoggerAppender Class Referenceabstract

Implements passing LoggerEvent to target destination. More...

#include <Logger.qm.dox.h>

Inheritance diagram for Logger::LoggerAppender:
[legend]

Public Member Methods

 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< 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...
 
 processEvent (int type, auto params)
 Processes an event to the physical target. 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
 

Private Member Methods

*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. More...
 
abstract auto serializeImpl (LoggerEvent event)
 Serializes the given event to put in the queue or write to the target device. More...
 

Private:Internal Attributes

bool active = False
 An inactive appender won't accept any logging request.
 
list< LoggerFilterfilters
 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
filterthe new filter to add
topif 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-ERRORthrown if the filter is already in the list

◆ constructor()

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

Creates the object.

Parameters
namethe 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 processEvent() method in case of synchronous processing.

See also
processEvent()
Parameters
eventthe event to post
Returns
True if the event has been posted, False if not (filtered out, appender inactive, event not accepted on queue, etc)

◆ processEvent()

Logger::LoggerAppender::processEvent ( int  type,
auto  params 
)

Processes an event to the physical target.

See also
serializeImpl()
Parameters
typesee "EVENT_xxx" constants
paramsprocessing parameters

◆ 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
typesee "EVENT_xxx" constants
paramsprocessing parameters

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

◆ pushEvent()

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

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

Parameters
typethe event type
paramsparameters for the event according to the event type
Returns
True if the event was accepted/processed, False if not
See also
processEvent()

◆ removeFilter()

Logger::LoggerAppender::removeFilter ( LoggerFilter  filter)

Removes the given filter from the filter chain.

Parameters
filterthe filter to remove

◆ serializeImpl()

abstract auto Logger::LoggerAppender::serializeImpl ( LoggerEvent  event)
privatepure 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 processEvent() method in the params argument when type is EVENT_LOG.

Returns
the serialized event

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

◆ 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-ERRORthrown if appender is opened