From f0cd9d15308007aa84068d0373b52bcaa67e3823 Mon Sep 17 00:00:00 2001 From: zydxhs Date: Fri, 2 Dec 2022 15:51:34 +0800 Subject: [PATCH] dup_filter_sink adds parameters to enable setting the level of skipped logs (#2563) * dup_filter_sink adds parameters to enable setting the level of skipped logs * rename the param name 'level' to 'notification_level' Co-authored-by: zhuyadong --- include/spdlog/sinks/dup_filter_sink.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/include/spdlog/sinks/dup_filter_sink.h b/include/spdlog/sinks/dup_filter_sink.h index 1a4fb348..3c96549c 100644 --- a/include/spdlog/sinks/dup_filter_sink.h +++ b/include/spdlog/sinks/dup_filter_sink.h @@ -20,7 +20,7 @@ // #include // // int main() { -// auto dup_filter = std::make_shared(std::chrono::seconds(5)); +// auto dup_filter = std::make_shared(std::chrono::seconds(5), level::info); // dup_filter->add_sink(std::make_shared()); // spdlog::logger l("logger", dup_filter); // l.info("Hello"); @@ -41,8 +41,9 @@ class dup_filter_sink : public dist_sink { public: template - explicit dup_filter_sink(std::chrono::duration max_skip_duration) + explicit dup_filter_sink(std::chrono::duration max_skip_duration, level::level_enum notification_level = level::info) : max_skip_duration_{max_skip_duration} + , log_level_{notification_level} {} protected: @@ -50,6 +51,7 @@ protected: log_clock::time_point last_msg_time_; std::string last_msg_payload_; size_t skip_counter_ = 0; + level::level_enum log_level_; void sink_it_(const details::log_msg &msg) override { @@ -67,7 +69,7 @@ protected: auto msg_size = ::snprintf(buf, sizeof(buf), "Skipped %u duplicate messages..", static_cast(skip_counter_)); if (msg_size > 0 && static_cast(msg_size) < sizeof(buf)) { - details::log_msg skipped_msg{msg.source, msg.logger_name, level::info, string_view_t{buf, static_cast(msg_size)}}; + details::log_msg skipped_msg{msg.source, msg.logger_name, log_level_, string_view_t{buf, static_cast(msg_size)}}; dist_sink::sink_it_(skipped_msg); } }