mirror of
https://github.com/gabime/spdlog.git
synced 2025-02-28 11:15:50 +08:00
refactor async sink
This commit is contained in:
parent
9673c1ba09
commit
82358e8ebe
@ -94,7 +94,7 @@ private:
|
|||||||
using async_log_msg = details::async_log_msg;
|
using async_log_msg = details::async_log_msg;
|
||||||
using queue_t = details::mpmc_blocking_queue<async_log_msg>;
|
using queue_t = details::mpmc_blocking_queue<async_log_msg>;
|
||||||
|
|
||||||
void send_message_(async_log_msg::type msg_type, const details::log_msg &msg) const;
|
void enqueue_message_(details::async_log_msg &&msg) const;
|
||||||
void backend_loop_();
|
void backend_loop_();
|
||||||
void backend_log_(const details::log_msg &msg) ;
|
void backend_log_(const details::log_msg &msg) ;
|
||||||
void backend_flush_();
|
void backend_flush_();
|
||||||
|
@ -45,10 +45,12 @@ async_sink::~async_sink() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void async_sink::log(const details::log_msg &msg) { send_message_(async_log_msg::type::log, msg); }
|
void async_sink::log(const details::log_msg &msg) {
|
||||||
|
enqueue_message_(async_log_msg(async_log_msg::type::log, msg));
|
||||||
|
}
|
||||||
|
|
||||||
void async_sink::flush() {
|
void async_sink::flush() {
|
||||||
send_message_(async_log_msg::type::flush, details::log_msg());
|
enqueue_message_(details::async_log_msg(async_log_msg::type::flush));
|
||||||
}
|
}
|
||||||
|
|
||||||
void async_sink::set_pattern(const std::string &pattern) { set_formatter(std::make_unique<pattern_formatter>(pattern)); }
|
void async_sink::set_pattern(const std::string &pattern) { set_formatter(std::make_unique<pattern_formatter>(pattern)); }
|
||||||
@ -94,16 +96,16 @@ void async_sink::reset_discard_counter() const { q_->reset_discard_counter(); }
|
|||||||
const async_sink::config &async_sink::get_config() const { return config_; }
|
const async_sink::config &async_sink::get_config() const { return config_; }
|
||||||
|
|
||||||
// private methods
|
// private methods
|
||||||
void async_sink::send_message_(async_log_msg::type msg_type, const details::log_msg &msg) const {
|
void async_sink::enqueue_message_(details::async_log_msg &&msg) const {
|
||||||
switch (config_.policy) {
|
switch (config_.policy) {
|
||||||
case overflow_policy::block:
|
case overflow_policy::block:
|
||||||
q_->enqueue(async_log_msg(msg_type, msg));
|
q_->enqueue(std::move(msg));
|
||||||
break;
|
break;
|
||||||
case overflow_policy::overrun_oldest:
|
case overflow_policy::overrun_oldest:
|
||||||
q_->enqueue_nowait(async_log_msg(msg_type, msg));
|
q_->enqueue_nowait(std::move(msg));
|
||||||
break;
|
break;
|
||||||
case overflow_policy::discard_new:
|
case overflow_policy::discard_new:
|
||||||
q_->enqueue_if_have_room(async_log_msg(msg_type, msg));
|
q_->enqueue_if_have_room(std::move(msg));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(false);
|
assert(false);
|
||||||
|
Loading…
Reference in New Issue
Block a user