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 69ae8d4 commit ebb641d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
2 changes: 1 addition & 1 deletion include/quill/backend/SignalHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ QUILL_BEGIN_NAMESPACE

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

/***/
class SignalHandlerContext
Expand Down
16 changes: 4 additions & 12 deletions include/quill/core/LoggerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class LoggerManager
}

/***/
QUILL_NODISCARD LoggerBase* get_valid_logger(std::initializer_list<std::string_view> exclude_logger_substrs = {}) const
QUILL_NODISCARD LoggerBase* get_valid_logger(std::string_view exclude_logger_substr = {}) const
{
// Retrieves any valid logger without the need for constructing a vector
LockGuard const lock{_spinlock};
Expand All @@ -80,19 +80,11 @@ class LoggerManager
// we can not add invalidated loggers as they can be removed at any time
if (elem->is_valid_logger())
{
// Check if any of the excluded substrings are found in the logger name
if (std::any_of(exclude_logger_substrs.begin(), exclude_logger_substrs.end(),
[&elem](std::string_view exclude_substr)
{
return elem->get_logger_name().find(exclude_substr) != std::string::npos;
}))
if (elem->get_logger_name().find(exclude_logger_substr) == std::string::npos)
{
// Skip this logger since it matches an excluded substring
continue;
// Use this logger since it doesn't include the an excluded substring
return elem.get();
}

// No excluded substring found, return this logger
return elem.get();
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/integration_tests/SignalHandlerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

#include "misc/TestUtilities.h"
#include "quill/Backend.h"
#include "quill/CsvWriter.h"
#include "quill/Frontend.h"
#include "quill/LogMacros.h"
#include "quill/CsvWriter.h"
#include "quill/sinks/FileSink.h"

#include <cstdio>
#include <memory>
#include <string>
#include <string_view>
#include <vector>
#include <memory>

using namespace quill;

Expand Down

0 comments on commit ebb641d

Please sign in to comment.