From 361344912ee6665cf42f2e9e4f5a4e4be12a309d Mon Sep 17 00:00:00 2001 From: gabime Date: Sun, 21 May 2017 02:45:08 +0300 Subject: [PATCH] Refactored message counter a little --- include/spdlog/details/async_logger_impl.h | 3 +++ include/spdlog/details/logger_impl.h | 16 +++------------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/include/spdlog/details/async_logger_impl.h b/include/spdlog/details/async_logger_impl.h index 487c628a..30e08477 100644 --- a/include/spdlog/details/async_logger_impl.h +++ b/include/spdlog/details/async_logger_impl.h @@ -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 diff --git a/include/spdlog/details/logger_impl.h b/include/spdlog/details/logger_impl.h index 820623db..722d8fc9 100644 --- a/include/spdlog/details/logger_impl.h +++ b/include/spdlog/details/logger_impl.h @@ -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) {