diff --git a/include/spdlog/details/logger_impl.h b/include/spdlog/details/logger_impl.h index 7f94c625..7d58c855 100644 --- a/include/spdlog/details/logger_impl.h +++ b/include/spdlog/details/logger_impl.h @@ -65,7 +65,11 @@ 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) @@ -86,7 +90,11 @@ 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) @@ -108,7 +116,9 @@ 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) diff --git a/include/spdlog/details/pattern_formatter_impl.h b/include/spdlog/details/pattern_formatter_impl.h index 95ccda21..27c43c75 100644 --- a/include/spdlog/details/pattern_formatter_impl.h +++ b/include/spdlog/details/pattern_formatter_impl.h @@ -652,9 +652,11 @@ inline void spdlog::pattern_formatter::handle_flag(char flag) _formatters.push_back(std::unique_ptr(new details::pid_formatter())); break; +#if defined(SPDLOG_ENABLE_MESSAGE_COUNTER) case ('i'): _formatters.push_back(std::unique_ptr(new details::i_formatter())); break; +#endif default: //Unknown flag appears as is _formatters.push_back(std::unique_ptr(new details::ch_formatter('%'))); diff --git a/include/spdlog/tweakme.h b/include/spdlog/tweakme.h index c167c716..9cbd4096 100644 --- a/include/spdlog/tweakme.h +++ b/include/spdlog/tweakme.h @@ -120,3 +120,10 @@ // // #define SPDLOG_FINAL final /////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +// Uncomment to enable message counting feature. Adds %i logger pattern that +// prints log message sequence id. +// +// #define SPDLOG_ENABLE_MESSAGE_COUNTER +///////////////////////////////////////////////////////////////////////////////