file sinks refactoring

This commit is contained in:
gabi
2014-01-26 01:53:23 +02:00
parent 9727692a83
commit f7dd08c235
5 changed files with 93 additions and 95 deletions

View File

@@ -32,7 +32,6 @@ protected:
private:
c11log::logger::sinks_vector_t sinks_;
std::atomic<bool> active_ { true };
const std::chrono::seconds push_pop_timeout_;
c11log::details::blocking_queue<std::string> q_;
std::thread back_thread_;
//Clear all remaining messages(if any), stop the back_thread_ and join it
@@ -47,7 +46,6 @@ private:
inline c11log::sinks::async_sink::async_sink(const std::size_t max_queue_size)
:q_(max_queue_size),
push_pop_timeout_(std::chrono::seconds(2)),
back_thread_(&async_sink::thread_loop_, this)
{}
@@ -57,19 +55,20 @@ inline c11log::sinks::async_sink::~async_sink()
}
inline void c11log::sinks::async_sink::sink_it_(const std::string& msg)
{
q_.push(msg, push_pop_timeout_);
q_.push(msg);
}
inline void c11log::sinks::async_sink::thread_loop_()
{
std::string msg;
auto pop_timeout = std::chrono::seconds(1);
while (active_)
{
if (q_.pop(msg, push_pop_timeout_))
if (q_.pop(msg, pop_timeout))
{
for (auto &sink : sinks_)
{
sink->log(msg, _level);
sink->log(msg, static_cast<level::level_enum>(_level.load()));
if (!active_)
return;
}