This commit is contained in:
gabime
2016-08-05 04:43:20 +03:00
parent bdbe908693
commit e7debaacd7
11 changed files with 715 additions and 691 deletions

View File

@@ -120,7 +120,7 @@ public:
async_log_helper(formatter_ptr formatter,
const std::vector<sink_ptr>& sinks,
size_t queue_size,
const log_err_handler err_handler,
const log_err_handler err_handler,
const async_overflow_policy overflow_policy = async_overflow_policy::block_retry,
const std::function<void()>& worker_warmup_cb = nullptr,
const std::chrono::milliseconds& flush_interval_ms = std::chrono::milliseconds::zero(),
@@ -143,13 +143,13 @@ private:
// queue of messages to log
q_type _q;
log_err_handler _err_handler;
log_err_handler _err_handler;
bool _flush_requested;
bool _terminate_requested;
// overflow policy
const async_overflow_policy _overflow_policy;
@@ -166,7 +166,7 @@ private:
std::thread _worker_thread;
void push_msg(async_msg&& new_msg);
// worker thread main loop
void worker_loop();
@@ -178,7 +178,7 @@ 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);
};
}
}
@@ -190,7 +190,7 @@ inline spdlog::details::async_log_helper::async_log_helper(
formatter_ptr formatter,
const std::vector<sink_ptr>& sinks,
size_t queue_size,
log_err_handler err_handler,
log_err_handler err_handler,
const async_overflow_policy overflow_policy,
const std::function<void()>& worker_warmup_cb,
const std::chrono::milliseconds& flush_interval_ms,
@@ -198,7 +198,7 @@ inline spdlog::details::async_log_helper::async_log_helper(
_formatter(formatter),
_sinks(sinks),
_q(queue_size),
_err_handler(err_handler),
_err_handler(err_handler),
_flush_requested(false),
_terminate_requested(false),
_overflow_policy(overflow_policy),
@@ -231,7 +231,7 @@ inline void spdlog::details::async_log_helper::log(const details::log_msg& msg)
}
inline void spdlog::details::async_log_helper::push_msg(details::async_log_helper::async_msg&& new_msg)
{
{
if (!_q.enqueue(std::move(new_msg)) && _overflow_policy != async_overflow_policy::discard_log_msg)
{
auto last_op_time = details::os::now();
@@ -261,12 +261,14 @@ inline void spdlog::details::async_log_helper::worker_loop()
while(process_next_msg(last_pop, last_flush));
if (_worker_teardown_cb) _worker_teardown_cb();
}
catch (const std::exception &ex) {
_err_handler(ex.what());
}
catch (...) {
_err_handler("Unknown exception");
}
catch (const std::exception &ex)
{
_err_handler(ex.what());
}
catch (...)
{
_err_handler("Unknown exception");
}
}
// process next message in the queue