diff --git a/include/spdlog/sinks/dup_filter_sink.h b/include/spdlog/sinks/dup_filter_sink.h index ad208ffb..0a71f0f7 100644 --- a/include/spdlog/sinks/dup_filter_sink.h +++ b/include/spdlog/sinks/dup_filter_sink.h @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include #include @@ -62,11 +62,14 @@ protected: // log the "skipped.." message if (skip_counter_ > 0) - { - memory_buf_t buf; - fmt::format_to(buf, "Skipped {} duplicate messages..", skip_counter_); - details::log_msg skipped_msg{msg.logger_name, level::info, string_view_t{buf.data(), buf.size()}}; - dist_sink::sink_it_(skipped_msg); + { + char buf[64]; + auto msg_size = ::snprintf(buf, sizeof(buf), "Skipped %u duplicate messages..", static_cast(skip_counter_)); + if (msg_size > 0 && msg_size < sizeof(buf)) + { + details::log_msg skipped_msg{msg.logger_name, level::info, string_view_t{buf, static_cast(msg_size)}}; + dist_sink::sink_it_(skipped_msg); + } } // log current message diff --git a/tests/test_dup_filter.cpp b/tests/test_dup_filter.cpp index 795278a0..a031f908 100644 --- a/tests/test_dup_filter.cpp +++ b/tests/test_dup_filter.cpp @@ -77,6 +77,7 @@ TEST_CASE("dup_filter_test5", "[dup_filter_sink]") dup_filter_sink_mt dup_sink{std::chrono::seconds{5}}; auto test_sink = std::make_shared(); + test_sink->set_pattern("%v"); dup_sink.add_sink(test_sink); dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message1"}); @@ -85,4 +86,6 @@ TEST_CASE("dup_filter_test5", "[dup_filter_sink]") dup_sink.log(spdlog::details::log_msg{"test", spdlog::level::info, "message2"}); REQUIRE(test_sink->msg_counter() == 3); // skip 2 messages but log the "skipped.." message before message2 + REQUIRE(test_sink->lines()[1] == "Skipped 2 duplicate messages.."); + }