From ef44b57485cce658d831b02611613a424971811b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Kubern=C3=A1t?= Date: Thu, 13 Jun 2024 18:12:13 +0200 Subject: [PATCH] Make log macros into expressions --- libnecrolog/necrolog.cpp | 2 +- libnecrolog/necrolog.h | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/libnecrolog/necrolog.cpp b/libnecrolog/necrolog.cpp index 33774a9..07f5e1e 100644 --- a/libnecrolog/necrolog.cpp +++ b/libnecrolog/necrolog.cpp @@ -1,8 +1,8 @@ #include "necrolog.h" +#include #include #include -#include #include #include diff --git a/libnecrolog/necrolog.h b/libnecrolog/necrolog.h index 312a770..ab122a5 100644 --- a/libnecrolog/necrolog.h +++ b/libnecrolog/necrolog.h @@ -128,10 +128,12 @@ class NECROLOG_DECL_EXPORT NecroLog #else #define nCDebug(topic) for(bool necrolog__en__ = NecroLog::shouldLog(NecroLog::Level::Debug, NecroLog::LogContext(__FILE__, __LINE__, topic)); necrolog__en__; necrolog__en__ = false) NecroLog::create(NecroLog::Level::Debug, NecroLog::LogContext(__FILE__, __LINE__, topic)) #endif -#define nCInfo(topic) for(bool necrolog__en__ = NecroLog::shouldLog(NecroLog::Level::Info, NecroLog::LogContext(__FILE__, __LINE__, topic)); necrolog__en__; necrolog__en__ = false) NecroLog::create(NecroLog::Level::Info, NecroLog::LogContext(__FILE__, __LINE__, topic)) -#define nCMessage(topic) for(bool necrolog__en__ = NecroLog::shouldLog(NecroLog::Level::Message, NecroLog::LogContext(__FILE__, __LINE__, topic)); necrolog__en__; necrolog__en__ = false) NecroLog::create(NecroLog::Level::Message, NecroLog::LogContext(__FILE__, __LINE__, topic)) -#define nCWarning(topic) for(bool necrolog__en__ = NecroLog::shouldLog(NecroLog::Level::Warning, NecroLog::LogContext(__FILE__, __LINE__, topic)); necrolog__en__; necrolog__en__ = false) NecroLog::create(NecroLog::Level::Warning, NecroLog::LogContext(__FILE__, __LINE__, topic)) -#define nCError(topic) for(bool necrolog__en__ = NecroLog::shouldLog(NecroLog::Level::Error, NecroLog::LogContext(__FILE__, __LINE__, topic)); necrolog__en__; necrolog__en__ = false) NecroLog::create(NecroLog::Level::Error, NecroLog::LogContext(__FILE__, __LINE__, topic)) + +#define NECROLOG_IMPL_LOG_MACRO(level, topic) !NecroLog::shouldLog(NecroLog::Level::level, NecroLog::LogContext(__FILE__, __LINE__, topic)) ? NecroLog::create(NecroLog::Level::level, NecroLog::LogContext(__FILE__, __LINE__, topic)) : NecroLog::create(NecroLog::Level::level, NecroLog::LogContext(__FILE__, __LINE__, topic)) +#define nCInfo(topic) NECROLOG_IMPL_LOG_MACRO(Info, topic) +#define nCMessage(topic) NECROLOG_IMPL_LOG_MACRO(Message, topic) +#define nCWarning(topic) NECROLOG_IMPL_LOG_MACRO(Warning, topic) +#define nCError(topic) NECROLOG_IMPL_LOG_MACRO(Error, topic) #define nDebug() nCDebug("") #define nMessage() nCMessage("")