我正在使用Boost.Log异步接收器(请参阅Asynchronous sink frontend)。要正确关机,必须正常停止并冲洗记录到异步接收器的馈送。核心具有添加和移除汇的方法,但似乎没有办法让客户获得汇或访问它们。该文档具有stop_logging
方法,如何在使用Boost.Log时停止所有异步接收器
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();
}
,但它需要一个特定sink_t
类型。前端类具有用于接收器后端和排队策略的模板参数。
template<typename SinkBackendT,
typename QueueingStrategyT = unbounded_fifo_queue>
class asynchronous_sink;
我都会有几种不同类型的汇,所以我想有持有它们的通用容器,这样我就可以简单的叠代,并呼吁stop_logging
每个沉在容器中。
这实际上是一个关于C++模板化数据结构的常见问题,由于Boost.Log提供的接口,我需要解决这些问题。什么是一个好的数据结构来跟踪我添加到Boost.Log内核的异步接收器?我需要一个,所以我可以在关机时致电stop_logging
。
我的第一个简单的方法是有一个向量boost::any
对象。但是这很麻烦,不雅。我怀疑一个合理的方法是使用lambda方法调用stop_logging
的函数对象的向量。但是我迷失在模板类型中,不知道如何去做。
我很感激任何帮助。 谢谢!