Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move messageHandler out of globalOptions #26

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions libnecrolog/necrolog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
#include <unistd.h>
#endif

namespace {
NecroLog::MessageHandler messageHandler = NecroLog::defaultMessageHandler; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
}

NecroLog::Options &NecroLog::globalOptions()
{
static Options global_options;
Expand Down Expand Up @@ -101,7 +105,7 @@ bool NecroLog::shouldLog(Level level, const LogContext &context)

NecroLog::MessageHandler NecroLog::setMessageHandler(NecroLog::MessageHandler h)
{
return std::exchange(globalOptions().messageHandler, h);
return std::exchange(messageHandler, h);
}

namespace {
Expand Down Expand Up @@ -327,9 +331,8 @@ NecroLog::NecroLogSharedData::NecroLogSharedData(NecroLog::Level level, const Ne

NecroLog::NecroLogSharedData::~NecroLogSharedData()
{
auto h = globalOptions().messageHandler;
if(h)
h(m_level, m_logContext, m_os.str());
if(messageHandler)
messageHandler(m_level, m_logContext, m_os.str());
}

int NecroLog::moduleNameStart(const char *file_name)
Expand Down
1 change: 0 additions & 1 deletion libnecrolog/necrolog.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ class NECROLOG_DECL_EXPORT NecroLog
bool logLongFileNames = false;
bool caseInsensitiveTopicMatch = false;
ColorizedOutputMode colorizedOutput = ColorizedOutputMode::IfTty;
MessageHandler messageHandler = defaultMessageHandler;
};

static Options& globalOptions();
Expand Down
Loading