mirror of
https://github.com/gabime/spdlog.git
synced 2025-09-29 09:59:33 +08:00
file sinks refactoring
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user