From 912da77783e5881681a7267fbaa50d1fd5800c20 Mon Sep 17 00:00:00 2001 From: Aleksandar Levic Date: Wed, 7 Sep 2022 15:28:44 +0200 Subject: [PATCH] chore: Change way of reporting dropped messages to built-in error handler --- include/spdlog/async_logger-inl.h | 12 ++++++------ tests/test_async.cpp | 1 - 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/include/spdlog/async_logger-inl.h b/include/spdlog/async_logger-inl.h index 2c733532..7a093162 100644 --- a/include/spdlog/async_logger-inl.h +++ b/include/spdlog/async_logger-inl.h @@ -67,19 +67,19 @@ SPDLOG_INLINE void spdlog::async_logger::backend_sink_it_(const details::log_msg } } + if (should_flush_(msg)) + { + backend_flush_(); + } + if (auto pool_ptr = thread_pool_.lock()) { auto lost_messages = pool_ptr->overrun_counter(); if (lost_messages > 0) { - spdlog::debug("Lost {} messages.", lost_messages); + err_handler_(fmt::format("Lost {} messages.", lost_messages)); pool_ptr->reset_overrun_counter(); } } - - if (should_flush_(msg)) - { - backend_flush_(); - } } SPDLOG_INLINE void spdlog::async_logger::backend_flush_() diff --git a/tests/test_async.cpp b/tests/test_async.cpp index 5265bca4..b19e62c8 100644 --- a/tests/test_async.cpp +++ b/tests/test_async.cpp @@ -40,7 +40,6 @@ TEST_CASE("discard policy ", "[async]") logger->info("Hello message"); } REQUIRE(test_sink->msg_counter() < messages); - REQUIRE(tp->overrun_counter() > 0); } TEST_CASE("discard policy using factory ", "[async]")