This commit is contained in:
gabime 2016-08-22 22:09:23 +03:00
parent 4f52cc4dec
commit 332b7c0d7f
3 changed files with 90 additions and 99 deletions

View File

@ -60,8 +60,8 @@ public:
const std::chrono::milliseconds& flush_interval_ms = std::chrono::milliseconds::zero(),
const std::function<void()>& worker_teardown_cb = nullptr);
//Wait for the queue to be empty, and flush synchronously
//Warning: this can potentialy last forever as we wait it to complete
//Wait for the queue to be empty, and flush synchronously
//Warning: this can potentialy last forever as we wait it to complete
void flush() override;
protected:
void _sink_it(details::log_msg& msg) override;

View File

@ -78,7 +78,7 @@ async_msg(async_msg&& other) SPDLOG_NOEXCEPT:
txt = std::move(other.txt);
msg_type = other.msg_type;
return *this;
}
}
// never copy or assign. should only be moved..
async_msg(const async_msg&) = delete;
@ -179,8 +179,8 @@ private:
// sleep,yield or return immediatly using the time passed since last message as a hint
static void sleep_or_yield(const spdlog::log_clock::time_point& now, const log_clock::time_point& last_op_time);
// wait until the queue is empty
void wait_empty_q();
// wait until the queue is empty
void wait_empty_q();
};
}
@ -252,9 +252,9 @@ inline void spdlog::details::async_log_helper::push_msg(details::async_log_helpe
//wait for the queue be empty and request flush from its sinks
inline void spdlog::details::async_log_helper::flush()
{
wait_empty_q();
wait_empty_q();
push_msg(async_msg(async_msg_type::flush));
wait_empty_q(); //make sure the above flush message was processed
wait_empty_q(); //make sure the above flush message was processed
}
inline void spdlog::details::async_log_helper::worker_loop()
@ -369,10 +369,11 @@ inline void spdlog::details::async_log_helper::sleep_or_yield(const spdlog::log_
// wait for the queue to be empty
inline void spdlog::details::async_log_helper::wait_empty_q()
{
auto last_op = details::os::now();
while (_q.approx_size() > 0) {
sleep_or_yield(details::os::now(), last_op);
}
auto last_op = details::os::now();
while (_q.approx_size() > 0)
{
sleep_or_yield(details::os::now(), last_op);
}
}

View File

@ -1,10 +0,0 @@
[2016-08-20 13:50:56.499] [logger] [info] Test message 0
[2016-08-20 13:50:56.499] [logger] [info] Test message 1
[2016-08-20 13:50:56.499] [logger] [info] Test message 2
[2016-08-20 13:50:56.499] [logger] [info] Test message 3
[2016-08-20 13:50:56.499] [logger] [info] Test message 4
[2016-08-20 13:50:56.499] [logger] [info] Test message 5
[2016-08-20 13:50:56.500] [logger] [info] Test message 6
[2016-08-20 13:50:56.500] [logger] [info] Test message 7
[2016-08-20 13:50:56.500] [logger] [info] Test message 8
[2016-08-20 13:50:56.500] [logger] [info] Test message 9