Refactored message counter a little

This commit is contained in:
gabime 2017-05-21 02:45:08 +03:00
parent 7da3e47ddc
commit 361344912e
2 changed files with 6 additions and 13 deletions

View File

@ -87,6 +87,9 @@ inline void spdlog::async_logger::_sink_it(details::log_msg& msg)
{
try
{
#if defined(SPDLOG_ENABLE_MESSAGE_COUNTER)
msg.msg_id = _msg_counter.fetch_add(1, std::memory_order_relaxed);
#endif
_async_log_helper->log(msg);
if (_should_flush_on(msg))
_async_log_helper->flush(false); // do async flush

View File

@ -68,11 +68,6 @@ inline void spdlog::logger::log(level::level_enum lvl, const char* fmt, const Ar
{
details::log_msg log_msg(&_name, lvl);
log_msg.raw.write(fmt, args...);
#if defined(SPDLOG_ENABLE_MESSAGE_COUNTER)
log_msg.msg_id = _msg_counter.fetch_add(1, std::memory_order_relaxed);
#endif
_sink_it(log_msg);
}
catch (const std::exception &ex)
@ -93,11 +88,6 @@ inline void spdlog::logger::log(level::level_enum lvl, const char* msg)
{
details::log_msg log_msg(&_name, lvl);
log_msg.raw << msg;
#if defined(SPDLOG_ENABLE_MESSAGE_COUNTER)
log_msg.msg_id = _msg_counter.fetch_add(1, std::memory_order_relaxed);
#endif
_sink_it(log_msg);
}
catch (const std::exception &ex)
@ -119,9 +109,6 @@ inline void spdlog::logger::log(level::level_enum lvl, const T& msg)
{
details::log_msg log_msg(&_name, lvl);
log_msg.raw << msg;
#if defined(SPDLOG_ENABLE_MESSAGE_COUNTER)
log_msg.msg_id = _msg_counter.fetch_add(1, std::memory_order_relaxed);
#endif
_sink_it(log_msg);
}
catch (const std::exception &ex)
@ -313,6 +300,9 @@ inline bool spdlog::logger::should_log(spdlog::level::level_enum msg_level) cons
//
inline void spdlog::logger::_sink_it(details::log_msg& msg)
{
#if defined(SPDLOG_ENABLE_MESSAGE_COUNTER)
msg.msg_id = _msg_counter.fetch_add(1, std::memory_order_relaxed);
#endif
_formatter->format(msg);
for (auto &sink : _sinks)
{