Commit 0035a0c9 authored by gabime's avatar gabime

Fixed dup sink compile warnings in older compilers with back_inserter

parent 036cc5d5
......@@ -7,7 +7,7 @@
#include <spdlog/details/null_mutex.h>
#include <spdlog/details/log_msg.h>
#include <iterator>
#include <cstdio>
#include <mutex>
#include <string>
#include <chrono>
......@@ -63,11 +63,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()}};
char buf[64];
auto msg_size = ::snprintf(buf, sizeof(buf), "Skipped %u duplicate messages..", static_cast<unsigned>(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<size_t>(msg_size)}};
dist_sink<Mutex>::sink_it_(skipped_msg);
}
}
// log current message
dist_sink<Mutex>::sink_it_(msg);
......
......@@ -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_mt>();
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..");
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment