mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-25 10:01:33 +08:00
fixed async_sink to use move instead of unique_ptr
This commit is contained in:
parent
0db417f9af
commit
ed17c9a4a9
@ -41,6 +41,7 @@
|
|||||||
#include "../details/blocking_queue.h"
|
#include "../details/blocking_queue.h"
|
||||||
#include "../details/null_mutex.h"
|
#include "../details/null_mutex.h"
|
||||||
#include "../details/log_msg.h"
|
#include "../details/log_msg.h"
|
||||||
|
#include "../details/format.h"
|
||||||
|
|
||||||
|
|
||||||
namespace spdlog
|
namespace spdlog
|
||||||
@ -52,7 +53,8 @@ namespace sinks
|
|||||||
class async_sink : public base_sink < details::null_mutex > //single worker thread so null_mutex
|
class async_sink : public base_sink < details::null_mutex > //single worker thread so null_mutex
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using q_type = details::blocking_queue < std::unique_ptr<details::log_msg> > ;
|
|
||||||
|
using q_type = details::blocking_queue < details::log_msg > ;
|
||||||
|
|
||||||
explicit async_sink(const q_type::size_type max_queue_size);
|
explicit async_sink(const q_type::size_type max_queue_size);
|
||||||
|
|
||||||
@ -109,10 +111,10 @@ inline spdlog::sinks::async_sink::~async_sink()
|
|||||||
inline void spdlog::sinks::async_sink::_sink_it(const details::log_msg& msg)
|
inline void spdlog::sinks::async_sink::_sink_it(const details::log_msg& msg)
|
||||||
{
|
{
|
||||||
_push_sentry();
|
_push_sentry();
|
||||||
_q.push(std::unique_ptr<details::log_msg>(new details::log_msg(msg)));
|
_q.push(std::move(msg));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void spdlog::sinks::async_sink::_thread_loop()
|
inline void spdlog::sinks::async_sink::_thread_loop()
|
||||||
{
|
{
|
||||||
std::chrono::seconds pop_timeout { 1 };
|
std::chrono::seconds pop_timeout { 1 };
|
||||||
@ -124,22 +126,24 @@ inline void spdlog::sinks::async_sink::_thread_loop()
|
|||||||
{
|
{
|
||||||
if (!_active)
|
if (!_active)
|
||||||
return;
|
return;
|
||||||
_formatter->format(*msg);
|
|
||||||
for (auto &s : _sinks)
|
try
|
||||||
{
|
{
|
||||||
try
|
|
||||||
{
|
_formatter->format(msg);
|
||||||
s->log(*msg);
|
for (auto &s : _sinks)
|
||||||
}
|
s->log(msg);
|
||||||
catch (const std::exception& ex)
|
|
||||||
{
|
|
||||||
_last_backthread_ex = std::make_shared<spdlog_ex>(ex.what());
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
_last_backthread_ex = std::make_shared<spdlog_ex>("Unknown exception");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
catch (const std::exception& ex)
|
||||||
|
{
|
||||||
|
_last_backthread_ex = std::make_shared<spdlog_ex>(ex.what());
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
_last_backthread_ex = std::make_shared<spdlog_ex>("Unknown exception");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -178,7 +182,7 @@ inline void spdlog::sinks::async_sink::shutdown(const log_clock::duration& timeo
|
|||||||
_join();
|
_join();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
inline void spdlog::sinks::async_sink::_push_sentry()
|
inline void spdlog::sinks::async_sink::_push_sentry()
|
||||||
{
|
{
|
||||||
if (_last_backthread_ex)
|
if (_last_backthread_ex)
|
||||||
|
Loading…
Reference in New Issue
Block a user