|
Apache Log4cxx
Version 2.0.0
|
The AsyncAppender decouples logging event creation from output by processing log events asynchronously. More...
#include <asyncappender.h>
Public Member Functions | |
| AsyncAppender () | |
| Create new instance. | |
| virtual | ~AsyncAppender () |
| If not closed, calls AsyncAppender::close. | |
| void | addAppender (const AppenderPtr &newAppender) override |
Ensure newAppender receives any logging event added to this appender. | |
| void | doAppend (const spi::LoggingEventPtr &event) override |
| Call AppenderSkeleton::doAppendImpl without acquiring a lock. | |
| void | append (const spi::LoggingEventPtr &event) override |
Add event to a ring buffer. | |
| AppenderList | getAllAppenders () const override |
| Get iterator over attached appenders. | |
| AppenderPtr | getAppender (const LogString &name) const override |
| Get appender by name. | |
| bool | isAttached (const AppenderPtr &appender) const override |
| Determines if specified appender is attached. | |
| void | removeAllAppenders () override |
| Removes and closes all attached appenders. | |
| bool | removeAppender (const AppenderPtr &appender) override |
Remove appender. | |
| bool | removeAppender (const LogString &name) override |
Remove the name appender. | |
| bool | replaceAppender (const AppenderPtr &oldAppender, const AppenderPtr &newAppender) override |
Replace oldAppender with newAppender. | |
| void | replaceAppenders (const AppenderList &newList) override |
Replace any previously added appenders with newList. | |
| void | setBufferSize (int newSize) |
Use newSize (an integer value in the range 1 to 10 million) for the number of logging events the ring buffer can hold. | |
| int | getBufferSize () const |
| Gets the current buffer size. | |
| void | setBlocking (bool newValue) |
Use newValue for whether appender should block the calling thread if there is no space in the ring buffer. | |
| bool | getBlocking () const |
| Gets whether appender should block calling thread when ring buffer is full. | |
| void | setOption (const LogString &option, const LogString &value) override |
Override this method to set option to value. | |
| Public Member Functions inherited from log4cxx::spi::AppenderAttachable | |
| virtual | ~AppenderAttachable () |
| Public Member Functions inherited from log4cxx::helpers::Object | |
| virtual | ~Object () |
| virtual const helpers::Class & | getClass () const =0 |
| virtual bool | instanceof (const Class &clazz) const =0 |
| virtual const void * | cast (const Class &clazz) const =0 |
| Public Member Functions inherited from log4cxx::AppenderSkeleton | |
| AppenderSkeleton (const LayoutPtr &layout={}) | |
| virtual | ~AppenderSkeleton () |
| void | activateOptions () override |
| Activate the options that were previously set with calls to option setters. | |
| void | addFilter (const spi::FilterPtr &newFilter) override |
Add newFilter to end of the spi::Filter chain. | |
| void | clearFilters () override |
| Clear the spi::Filter chain. | |
| void | close () override |
| Release any resources allocated within the appender such as file handles, network connections, etc. | |
| const spi::ErrorHandlerPtr | getErrorHandler () const |
| The currently set spi::ErrorHandler for this Appender. | |
| spi::FilterPtr | getFilter () const override |
| The first spi::Filter in the filter chain for this Appender. | |
| const spi::FilterPtr | getFirstFilter () const |
| The first spi::Filter in the filter chain for this Appender. | |
| LayoutPtr | getLayout () const override |
| The currently set Layout for this appender. | |
| LogString | getName () const override |
| The name of this Appender. | |
| const LevelPtr | getThreshold () const |
| This appender's current threshold level. | |
| bool | isAsSevereAsThreshold (const LevelPtr &level) const |
Is level greater than or equal to this appender's threshold? | |
| void | setErrorHandler (const spi::ErrorHandlerPtr &newValue) |
Use newValue as the spi::ErrorHandler for this Appender. | |
| void | setLayout (const LayoutPtr &newValue) override |
Use newValue as the layout for this appender. | |
| void | setName (const LogString &newValue) override |
Use newValue for the name of this Appender. | |
| void | setThreshold (const LevelPtr &newValue) |
Use newValue as this appender's threshold level. | |
| void | activateOptions (helpers::Pool &) |
| Public Member Functions inherited from log4cxx::Appender | |
| virtual | ~Appender () |
| void | doAppend (const spi::LoggingEventPtr &event, helpers::Pool &pool) |
| virtual bool | requiresLayout () const |
| Public Member Functions inherited from log4cxx::spi::OptionHandler | |
| virtual | ~OptionHandler () |
| void | activateOptions (helpers::Pool &) |
Static Public Attributes | |
| static const int | MaxBufferedEventCount = 10000000 |
Additional Inherited Members | |
| Protected Member Functions inherited from log4cxx::AppenderSkeleton | |
| AppenderSkeleton (LOG4CXX_PRIVATE_PTR(AppenderSkeletonPrivate) priv) | |
| void | doAppendImpl (const spi::LoggingEventPtr &event) |
Call the AppenderSkeleton::append method if the level of event is not lower than this appender's threshold and no attached spi::Filter indicates event is rejected. | |
| bool | isAccepted (const spi::LoggingEventPtr &event) const |
Does no attached filter deny event or does an attached filter accept event? | |
The AsyncAppender decouples logging event creation from output by processing log events asynchronously.
The AsyncAppender stores the logging event in a bounded buffer and then returns control to the application. A separate thread forwards events to the attached appender(s).
An AsyncAppender is used when you configure a logger to be asynchronous. These AsyncAppender(s) use the default values for all options and they cannot be changed using configuration file entries. For more control over the AsyncAppender options, use appender-ref element in the logger configuration instead.
Important notes:
This appender is useful when outputting to a slow event sink, for example, unbuffered output to a file, a remote SMTP server or a database. Note that configuring a FileAppender to use buffered output usually results in lower overhead than attaching the FileAppender to an AsyncAppender as the inter-thread communication overhead can exceed the time to add a message to a buffer.
You can attach multiple appenders to an AsyncAppender by:
Here is a sample configuration file:
When the application produces logging events faster than the background thread is able to process, the bounded buffer can become full. In this situation AsyncAppender will either block until the bounded buffer has a free slot or discard the event. The Blocking property controls which behaviour is used. When events are discarded, the logged output will indicate this with a log message prefixed with Discarded. The output may contain one Discarded message per logger name, the logging event of the highest level for each logger whose events have been discarded.
To determine whether the application produces logging events faster than the background thread is able to process, enable Log4cxx internal debugging. The AsyncAppender will output a histogram of queue length frequencies when closed.
See AsyncAppender::setOption for details.
| log4cxx::AsyncAppender::AsyncAppender | ( | ) |
Create new instance.
|
virtual |
If not closed, calls AsyncAppender::close.
|
overridevirtual |
Ensure newAppender receives any logging event added to this appender.
| newAppender | appender to add, may not be null. |
Implements log4cxx::spi::AppenderAttachable.
|
overridevirtual |
Add event to a ring buffer.
The behaviour when the ring buffer is full is controlled by the Blocking property value.
Implements log4cxx::AppenderSkeleton.
|
overridevirtual |
Call AppenderSkeleton::doAppendImpl without acquiring a lock.
Reimplemented from log4cxx::AppenderSkeleton.
|
overridevirtual |
Get iterator over attached appenders.
Implements log4cxx::spi::AppenderAttachable.
|
overridevirtual |
Get appender by name.
| name | name, may not be null. |
Implements log4cxx::spi::AppenderAttachable.
| bool log4cxx::AsyncAppender::getBlocking | ( | ) | const |
Gets whether appender should block calling thread when ring buffer is full.
If false, messages will be counted by logger and a summary message added after the buffered events have been appended.
| int log4cxx::AsyncAppender::getBufferSize | ( | ) | const |
Gets the current buffer size.
|
overridevirtual |
Determines if specified appender is attached.
| appender | appender. |
Implements log4cxx::spi::AppenderAttachable.
|
overridevirtual |
Removes and closes all attached appenders.
Implements log4cxx::spi::AppenderAttachable.
|
overridevirtual |
|
overridevirtual |
|
overridevirtual |
Replace oldAppender with newAppender.
Implements log4cxx::spi::AppenderAttachable.
|
overridevirtual |
Replace any previously added appenders with newList.
Implements log4cxx::spi::AppenderAttachable.
| void log4cxx::AsyncAppender::setBlocking | ( | bool | newValue | ) |
Use newValue for whether appender should block the calling thread if there is no space in the ring buffer.
| newValue | true if appender should wait until space is available in the ring buffer. |
| void log4cxx::AsyncAppender::setBufferSize | ( | int | newSize | ) |
Use newSize (an integer value in the range 1 to 10 million) for the number of logging events the ring buffer can hold.
The ring buffer size cannot be changed once the appender has received an event.
|
overridevirtual |
Override this method to set option to value.
| Supported options | Supported values | Default value |
|---|---|---|
| BufferSize | 1..10000000 | 128 |
| Blocking | True,False | True |
Reimplemented from log4cxx::AppenderSkeleton.
|
static |