Skip to content

Commit

Permalink
exclude CSV loggers from logging error logs in signal handler when us…
Browse files Browse the repository at this point in the history
…ing CsvWriter
  • Loading branch information
odygrd committed Sep 24, 2024
1 parent 0e9bac0 commit e5e0272
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- [v7.3.0](#v730)
- [v7.2.2](#v722)
- [v7.2.1](#v721)
- [v7.2.0](#v720)
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions include/quill/backend/SignalHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ QUILL_BEGIN_NAMESPACE

namespace detail
{
static constexpr std::string_view excluded_logger_name_substr = {"__csv__"};

/***/
class SignalHandlerContext
{
Expand All @@ -60,6 +58,8 @@ class SignalHandlerContext
return instance;
}

static constexpr std::string_view excluded_logger_name_substr = {"__csv__"};

std::atomic<int32_t> signal_number{0};
std::atomic<uint32_t> lock{0};
std::atomic<uint32_t> backend_thread_id{0};
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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<LoggerImpl<TFrontendOptions>*>(logger_base);
Expand All @@ -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<LoggerImpl<TFrontendOptions>*>(logger_base);
Expand Down
3 changes: 2 additions & 1 deletion include/quill/core/LoggerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit e5e0272

Please sign in to comment.