From 6547675e4376ae821d99adb4a1bd80c117a175ee Mon Sep 17 00:00:00 2001 From: Alexander Zilberkant Date: Mon, 15 May 2017 20:07:24 +0300 Subject: [PATCH] Revert "Merge pull request #441 from alzix/count_discarded" This reverts commit 038733345a44aca8ce3baf1ce19e57d7844e22ee, reversing changes made to 862d2f6f3549aa64404b2a3fbfd1b0a637f7e093. --- include/spdlog/details/async_log_helper.h | 51 ++++------------------- include/spdlog/tweakme.h | 7 ---- tests/async_logger.cpp | 38 ----------------- 3 files changed, 9 insertions(+), 87 deletions(-) delete mode 100644 tests/async_logger.cpp diff --git a/include/spdlog/details/async_log_helper.h b/include/spdlog/details/async_log_helper.h index c5a147ec..1e454550 100644 --- a/include/spdlog/details/async_log_helper.h +++ b/include/spdlog/details/async_log_helper.h @@ -27,7 +27,6 @@ #include #include #include -#include namespace spdlog { @@ -186,12 +185,6 @@ private: // wait until the queue is empty void wait_empty_q(); - // counter for messages discarded due to queue overflow - std::atomic _discarded_msg_count; - - // handle discarded messages - void handle_discarded_msg(const std::string& logger_name); - }; } } @@ -218,8 +211,7 @@ inline spdlog::details::async_log_helper::async_log_helper( _worker_warmup_cb(worker_warmup_cb), _flush_interval_ms(flush_interval_ms), _worker_teardown_cb(worker_teardown_cb), - _worker_thread(&async_log_helper::worker_loop, this), - _discarded_msg_count(0) + _worker_thread(&async_log_helper::worker_loop, this) {} // Send to the worker thread termination message(level=off) @@ -245,24 +237,16 @@ inline void spdlog::details::async_log_helper::log(const details::log_msg& msg) inline void spdlog::details::async_log_helper::push_msg(details::async_log_helper::async_msg&& new_msg) { - if (!_q.enqueue(std::move(new_msg))) + if (!_q.enqueue(std::move(new_msg)) && _overflow_policy != async_overflow_policy::discard_log_msg) { - if (_overflow_policy != async_overflow_policy::discard_log_msg) + auto last_op_time = details::os::now(); + auto now = last_op_time; + do { - auto last_op_time = details::os::now(); - auto now = last_op_time; - do - { - now = details::os::now(); - sleep_or_yield(now, last_op_time); - } while (!_q.enqueue(std::move(new_msg))); - } - else - { -#if defined(SPDLOG_ASYNC_COUNT_DISCARDED_MSG) - _discarded_msg_count++; -#endif + now = details::os::now(); + sleep_or_yield(now, last_op_time); } + while (!_q.enqueue(std::move(new_msg))); } } @@ -321,10 +305,6 @@ inline bool spdlog::details::async_log_helper::process_next_msg(log_clock::time_ break; default: -#if defined(SPDLOG_ASYNC_COUNT_DISCARDED_MSG) - handle_discarded_msg(incoming_async_msg.logger_name); -#endif - log_msg incoming_log_msg; incoming_async_msg.fill_log_msg(incoming_log_msg); _formatter->format(incoming_log_msg); @@ -409,18 +389,5 @@ inline void spdlog::details::async_log_helper::set_error_handler(spdlog::log_err _err_handler = err_handler; } -inline void spdlog::details::async_log_helper::handle_discarded_msg(const std::string& logger_name) -{ - unsigned int num_of_discarded_messages = _discarded_msg_count.exchange(0); - if (num_of_discarded_messages) - { - log_msg discarded_warning_msg(&logger_name, level::warn); - discarded_warning_msg.raw << "Discarded " << num_of_discarded_messages << " messages - logger queue overflow"; - _formatter->format(discarded_warning_msg); - for (auto &s : _sinks) - { - s->log(discarded_warning_msg); - } - } -} + diff --git a/include/spdlog/tweakme.h b/include/spdlog/tweakme.h index f1d25be6..c167c716 100644 --- a/include/spdlog/tweakme.h +++ b/include/spdlog/tweakme.h @@ -120,10 +120,3 @@ // // #define SPDLOG_FINAL final /////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -// Uncomment to count and print warning message about number of dropped messages. -// Only relevant for async_logger with async_overflow_policy::discard_log_msg -// -// #define SPDLOG_ASYNC_COUNT_DISCARDED_MSG -/////////////////////////////////////////////////////////////////////////////// diff --git a/tests/async_logger.cpp b/tests/async_logger.cpp deleted file mode 100644 index bcfb1ca6..00000000 --- a/tests/async_logger.cpp +++ /dev/null @@ -1,38 +0,0 @@ - -#include - -#include "includes.h" -#include "../include/spdlog/common.h" -#include "../include/spdlog/tweakme.h" - - -TEST_CASE("async_logging_overflow ", "[async_logging]") -{ - std::string filename = "logs/async_log_overflow.txt"; - auto sink = std::make_shared(filename, true); - auto logger = std::make_shared( - "overflow_logger", - sink, - 2, // queue size - spdlog::async_overflow_policy::discard_log_msg - ); - for (int i = 0; i < 8; i++) { - logger->info("Message #{}", i); - } - logger->flush(); - logger.reset(); - std::string the_log = file_contents(filename); -#if defined(SPDLOG_ASYNC_COUNT_DISCARDED_MSG) - std::cout << the_log << std::endl; - REQUIRE(the_log.find("Dropped 6 messages") != std::string::npos); -#endif -} - - - - - - - - -