From e5e02721b472df26aff1607ade1dbaad0cadbb0f Mon Sep 17 00:00:00 2001 From: Odysseas Georgoudis Date: Wed, 25 Sep 2024 00:43:09 +0100 Subject: [PATCH] exclude CSV loggers from logging error logs in signal handler when using CsvWriter --- CHANGELOG.md | 6 ++++++ include/quill/backend/SignalHandler.h | 10 +++++----- include/quill/core/LoggerManager.h | 3 ++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8b7526e..6e2aa995 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +- [v7.3.0](#v730) - [v7.2.2](#v722) - [v7.2.1](#v721) - [v7.2.0](#v720) @@ -77,6 +78,11 @@ - [v1.1.0](#v110) - [v1.0.0](#v100) +## v7.3.0 + +- Prevented error logs from the `SignalHandler` from being output to CSV files when a `CsvWriter` is in + use. ([#588](https://github.com/odygrd/quill/issues/588)) + ## v7.2.2 - Fixed race condition during DLL unload by ensuring safe cleanup of `ThreadContext` when diff --git a/include/quill/backend/SignalHandler.h b/include/quill/backend/SignalHandler.h index 58b553d1..839f1891 100644 --- a/include/quill/backend/SignalHandler.h +++ b/include/quill/backend/SignalHandler.h @@ -44,8 +44,6 @@ QUILL_BEGIN_NAMESPACE namespace detail { -static constexpr std::string_view excluded_logger_name_substr = {"__csv__"}; - /***/ class SignalHandlerContext { @@ -60,6 +58,8 @@ class SignalHandlerContext return instance; } + static constexpr std::string_view excluded_logger_name_substr = {"__csv__"}; + std::atomic signal_number{0}; std::atomic lock{0}; std::atomic backend_thread_id{0}; @@ -138,7 +138,7 @@ void on_signal(int32_t signal_number) else { // This means signal handler is running on a frontend thread, we can log and flush - LoggerBase* logger_base = detail::LoggerManager::instance().get_valid_logger(excluded_logger_name_substr); + LoggerBase* logger_base = detail::LoggerManager::instance().get_valid_logger(SignalHandlerContext::excluded_logger_name_substr); if (logger_base) { @@ -250,7 +250,7 @@ BOOL WINAPI on_console_signal(DWORD signal) (signal == CTRL_C_EVENT || signal == CTRL_BREAK_EVENT)) { // Log the interruption and flush log messages - LoggerBase* logger_base = detail::LoggerManager::instance().get_valid_logger(excluded_logger_name_substr); + LoggerBase* logger_base = detail::LoggerManager::instance().get_valid_logger(SignalHandlerContext::excluded_logger_name_substr); if (logger_base) { auto logger = reinterpret_cast*>(logger_base); @@ -277,7 +277,7 @@ LONG WINAPI on_exception(EXCEPTION_POINTERS* exception_p) if ((backend_thread_id != 0) && (current_thread_id != backend_thread_id)) { // Log the interruption and flush log messages - LoggerBase* logger_base = detail::LoggerManager::instance().get_valid_logger(excluded_logger_name_substr); + LoggerBase* logger_base = detail::LoggerManager::instance().get_valid_logger(SignalHandlerContext::excluded_logger_name_substr); if (logger_base) { auto logger = reinterpret_cast*>(logger_base); diff --git a/include/quill/core/LoggerManager.h b/include/quill/core/LoggerManager.h index d18bdd62..a06cba8b 100644 --- a/include/quill/core/LoggerManager.h +++ b/include/quill/core/LoggerManager.h @@ -81,7 +81,8 @@ class LoggerManager if (elem->is_valid_logger()) { // Return the logger only if it does not match the exclude_logger_substr - if (exclude_logger_substr.empty() || elem->get_logger_name().find(exclude_logger_substr) == std::string::npos) + if (exclude_logger_substr.empty() || + elem->get_logger_name().find(exclude_logger_substr) == std::string::npos) { // Return this logger if it's valid and not excluded return elem.get();