Boost  v1.57.0
doxygen for www.boost.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
boost::sinks::asynchronous_sink< SinkBackendT, QueueingStrategyT > Class Template Reference

Asynchronous logging sink frontend. More...

#include <async_frontend.hpp>

Inheritance diagram for boost::sinks::asynchronous_sink< SinkBackendT, QueueingStrategyT >:
Collaboration diagram for boost::sinks::asynchronous_sink< SinkBackendT, QueueingStrategyT >:

Public Types

typedef SinkBackendT sink_backend_type
 Sink implementation type. More...
 
typedef
boost::log::aux::locking_ptr
< sink_backend_type,
backend_mutex_type
locked_backend_ptr
 A pointer type that locks the backend until it's destroyed. More...
 
typedef
base_type::exception_handler_type 
exception_handler_type
 An exception handler type. More...
 

Public Member Functions

 asynchronous_sink (bool start_thread=true)
 Default constructor. More...
 
 asynchronous_sink (shared_ptr< sink_backend_type > const &backend, bool start_thread=true)
 Constructor attaches user-constructed backend instance. More...
 
 ~asynchronous_sink ()
 Destructor. More...
 
locked_backend_ptr locked_backend ()
 Locking accessor to the attached backend. More...
 
void consume (record_view const &rec)
 Enqueues the log record to the backend. More...
 
bool try_consume (record_view const &rec)
 The method attempts to pass logging record to the backend. More...
 
void run ()
 The method starts record feeding loop and effectively blocks until either of this happens: More...
 
void stop ()
 The method softly interrupts record feeding loop. More...
 
void feed_records ()
 The method feeds log records that may have been buffered to the backend and returns. More...
 
void flush ()
 The method feeds all log records that may have been buffered to the backend and returns. More...
 
template<typename FunT >
void set_filter (FunT const &filter)
 The method sets sink-specific filter functional object. More...
 
void reset_filter ()
 The method resets the filter. More...
 
template<typename FunT >
void set_exception_handler (FunT const &handler)
 The method sets an exception handler function. More...
 
void reset_exception_handler ()
 The method resets the exception handler function. More...
 
bool will_consume (attribute_value_set const &attrs)
 The method returns true if no filter is set or the attribute values pass the filter. More...
 
bool is_cross_thread () const BOOST_NOEXCEPT
 The method indicates that the sink passes log records between different threads. More...
 

Protected Types

typedef
boost::log::aux::light_rw_mutex 
mutex_type
 Mutex type. More...
 

Protected Member Functions

mutex_typefrontend_mutex () const
 Returns reference to the frontend mutex. More...
 
exception_handler_typeexception_handler ()
 Returns reference to the exception handler. More...
 
exception_handler_type const & exception_handler () const
 Returns reference to the exception handler. More...
 
template<typename BackendMutexT , typename BackendT >
void feed_record (record_view const &rec, BackendMutexT &backend_mutex, BackendT &backend)
 Feeds log record to the backend. More...
 
template<typename BackendMutexT , typename BackendT >
bool try_feed_record (record_view const &rec, BackendMutexT &backend_mutex, BackendT &backend)
 Attempts to feeds log record to the backend, does not block if backend_mutex is locked. More...
 
template<typename BackendMutexT , typename BackendT >
void flush_backend (BackendMutexT &backend_mutex, BackendT &backend)
 Flushes record buffers in the backend, if one supports it. More...
 

Detailed Description

template<typename SinkBackendT, typename QueueingStrategyT = unbounded_fifo_queue>
class boost::sinks::asynchronous_sink< SinkBackendT, QueueingStrategyT >

Asynchronous logging sink frontend.

The frontend starts a separate thread on construction. All logging records are passed to the backend in this dedicated thread only.

Member Typedef Documentation

template<typename SinkBackendT , typename QueueingStrategyT = unbounded_fifo_queue>
typedef boost::log::aux::locking_ptr< sink_backend_type, backend_mutex_type > boost::sinks::asynchronous_sink< SinkBackendT, QueueingStrategyT >::locked_backend_ptr

A pointer type that locks the backend until it's destroyed.

typedef boost::log::aux::light_rw_mutex boost::sinks::basic_sink_frontend::mutex_type
protectedinherited

Mutex type.

template<typename SinkBackendT , typename QueueingStrategyT = unbounded_fifo_queue>
typedef SinkBackendT boost::sinks::asynchronous_sink< SinkBackendT, QueueingStrategyT >::sink_backend_type

Sink implementation type.

Constructor & Destructor Documentation

template<typename SinkBackendT , typename QueueingStrategyT = unbounded_fifo_queue>
boost::sinks::asynchronous_sink< SinkBackendT, QueueingStrategyT >::asynchronous_sink ( bool  start_thread = true)
inline

Default constructor.

Constructs the sink backend instance. Requires the backend to be default-constructible.

Parameters
start_threadIf true, the frontend creates a thread to feed log records to the backend. Otherwise no thread is started and it is assumed that the user will call either run or feed_records himself.
template<typename SinkBackendT , typename QueueingStrategyT = unbounded_fifo_queue>
boost::sinks::asynchronous_sink< SinkBackendT, QueueingStrategyT >::asynchronous_sink ( shared_ptr< sink_backend_type > const &  backend,
bool  start_thread = true 
)
inlineexplicit

Constructor attaches user-constructed backend instance.

Parameters
backendPointer to the backend instance.
start_threadIf true, the frontend creates a thread to feed log records to the backend. Otherwise no thread is started and it is assumed that the user will call either run or feed_records himself.
Precondition
backend is not NULL.
template<typename SinkBackendT , typename QueueingStrategyT = unbounded_fifo_queue>
boost::sinks::asynchronous_sink< SinkBackendT, QueueingStrategyT >::~asynchronous_sink ( )
inline

Destructor.

Implicitly stops the dedicated feeding thread, if one is running.

References boost::sinks::asynchronous_sink< SinkBackendT, QueueingStrategyT >::stop().

Member Function Documentation

template<typename SinkBackendT , typename QueueingStrategyT = unbounded_fifo_queue>
void boost::sinks::asynchronous_sink< SinkBackendT, QueueingStrategyT >::consume ( record_view const &  rec)
inlinevirtual
exception_handler_type& boost::sinks::basic_sink_frontend::exception_handler ( )
inlineprotectedinherited

Returns reference to the exception handler.

exception_handler_type const& boost::sinks::basic_sink_frontend::exception_handler ( ) const
inlineprotectedinherited

Returns reference to the exception handler.

template<typename BackendMutexT , typename BackendT >
void boost::sinks::basic_sink_frontend::feed_record ( record_view const &  rec,
BackendMutexT &  backend_mutex,
BackendT &  backend 
)
inlineprotectedinherited
template<typename SinkBackendT , typename QueueingStrategyT = unbounded_fifo_queue>
void boost::sinks::asynchronous_sink< SinkBackendT, QueueingStrategyT >::feed_records ( )
inline

The method feeds log records that may have been buffered to the backend and returns.

Precondition
The sink frontend must be constructed without spawning a dedicated thread

References boost::sinks::basic_sink_frontend::frontend_mutex().

template<typename SinkBackendT , typename QueueingStrategyT = unbounded_fifo_queue>
void boost::sinks::asynchronous_sink< SinkBackendT, QueueingStrategyT >::flush ( )
inlinevirtual

The method feeds all log records that may have been buffered to the backend and returns.

Unlike feed_records, in case of ordering queueing the method also feeds records that were enqueued during the ordering window, attempting to empty the queue completely.

Precondition
The sink frontend must be constructed without spawning a dedicated thread

Implements boost::sinks::sink.

References boost::sinks::basic_sink_frontend::frontend_mutex(), boost::lock(), and boost::condition_variable_any::wait().

template<typename BackendMutexT , typename BackendT >
void boost::sinks::basic_sink_frontend::flush_backend ( BackendMutexT &  backend_mutex,
BackendT &  backend 
)
inlineprotectedinherited

Flushes record buffers in the backend, if one supports it.

Referenced by boost::sinks::unlocked_sink< SinkBackendT >::flush(), and boost::sinks::synchronous_sink< SinkBackendT >::flush().

bool boost::sinks::sink::is_cross_thread ( ) const
inlineinherited

The method indicates that the sink passes log records between different threads.

This information is needed by the logging core to detach log records from all thread-specific resources before passing it to the sink.

template<typename SinkBackendT , typename QueueingStrategyT = unbounded_fifo_queue>
locked_backend_ptr boost::sinks::asynchronous_sink< SinkBackendT, QueueingStrategyT >::locked_backend ( )
inline

Locking accessor to the attached backend.

void boost::sinks::basic_sink_frontend::reset_exception_handler ( )
inlineinherited

The method resets the exception handler function.

References boost::lock().

void boost::sinks::basic_sink_frontend::reset_filter ( )
inlineinherited

The method resets the filter.

References boost::lock(), and boost::filter::reset().

template<typename SinkBackendT , typename QueueingStrategyT = unbounded_fifo_queue>
void boost::sinks::asynchronous_sink< SinkBackendT, QueueingStrategyT >::run ( )
inline

The method starts record feeding loop and effectively blocks until either of this happens:

  • the thread is interrupted due to either standard thread interruption or a call to stop
  • an exception is thrown while processing a log record in the backend, and the exception is not terminated by the exception handler, if one is installed
Precondition
The sink frontend must be constructed without spawning a dedicated thread

References boost::sinks::basic_sink_frontend::feed_record(), and boost::sinks::basic_sink_frontend::frontend_mutex().

template<typename FunT >
void boost::sinks::basic_sink_frontend::set_exception_handler ( FunT const &  handler)
inlineinherited

The method sets an exception handler function.

References boost::lock().

template<typename FunT >
void boost::sinks::basic_sink_frontend::set_filter ( FunT const &  filter)
inlineinherited

The method sets sink-specific filter functional object.

References boost::lock().

template<typename SinkBackendT , typename QueueingStrategyT = unbounded_fifo_queue>
void boost::sinks::asynchronous_sink< SinkBackendT, QueueingStrategyT >::stop ( )
inline

The method softly interrupts record feeding loop.

This method must be called when the run method execution has to be interrupted. Unlike regular thread interruption, calling stop will not interrupt the record processing in the middle. Instead, the sink frontend will attempt to finish its business with the record in progress and return afterwards. This method can be called either if the sink was created with a dedicated thread, or if the feeding loop was initiated by user.

Note
Returning from this method does not guarantee that there are no records left buffered in the sink frontend. It is possible that log records keep coming during and after this method is called. At some point of execution of this method log records stop being processed, and all records that come after this point are put into the queue. These records will be processed upon further calls to run or feed_records.

References boost::sinks::basic_sink_frontend::frontend_mutex(), boost::lock(), boost::unique_lock< Mutex >::unlock(), and boost::condition_variable_any::wait().

Referenced by boost::sinks::asynchronous_sink< SinkBackendT, QueueingStrategyT >::~asynchronous_sink().

template<typename SinkBackendT , typename QueueingStrategyT = unbounded_fifo_queue>
bool boost::sinks::asynchronous_sink< SinkBackendT, QueueingStrategyT >::try_consume ( record_view const &  rec)
inlinevirtual

The method attempts to pass logging record to the backend.

Reimplemented from boost::sinks::sink.

template<typename BackendMutexT , typename BackendT >
bool boost::sinks::basic_sink_frontend::try_feed_record ( record_view const &  rec,
BackendMutexT &  backend_mutex,
BackendT &  backend 
)
inlineprotectedinherited

Attempts to feeds log record to the backend, does not block if backend_mutex is locked.

References boost::empty(), boost::lock(), boost::unique_lock< Mutex >::owns_lock(), boost::unique_lock< Mutex >::swap(), and boost::try_to_lock.

Referenced by boost::sinks::synchronous_sink< SinkBackendT >::try_consume().

bool boost::sinks::basic_sink_frontend::will_consume ( attribute_value_set const &  attrs)
inlinevirtualinherited

The method returns true if no filter is set or the attribute values pass the filter.

Parameters
attrsA set of attribute values of a logging record

Implements boost::sinks::sink.

References boost::lock().


The documentation for this class was generated from the following file: