I am using Boost.Log asynchronous sinks (see Asynchronous sink frontend). To have a proper shutdown, one must gracefully stop and flush the feeding of records to the async sinks. The core has methods for adding and removing sinks, but there does not seem to be a way for a client to get sinks or visit them. The documentation has a stop_logging
method,
void stop_logging(boost::shared_ptr< sink_t >& sink)
{
boost::shared_ptr< logging::core > core = logging::core::get();
// Remove the sink from the core, so that no records are passed to it
core->remove_sink(sink);
// Break the feeding loop
sink->stop();
// Flush all log records that may have left buffered
sink->flush();
sink.reset();
}
but it takes a specific sink_t
type. The asynchronous_sink frontend class has template arguments for the sink backend and queuing strategy.
template<typename SinkBackendT,
typename QueueingStrategyT = unbounded_fifo_queue>
class asynchronous_sink;
I will have several different kinds of sinks, so I would like to have a generic container that holds them, so I can simple iterate over it and call stop_logging
for each sink in the container.
This is really a general question about C++ templated data structures that I need to address because of the interface provided in Boost.Log. What is a good data structure to use to keep track of asynchronous sinks I have added to the Boost.Log core? I need one so I can call stop_logging
on shutdown.
My first simple-minded approach is to have a vector of boost::any
objects. But that is rather cumbersome and inelegant. I suspect that a reasonable approach would be to have a vector of function objects that are lambda methods calling stop_logging
. But I get lost in the template types and do not know how to do this.
I appreciate any help. Thanks!