Skip to content

Commit

Permalink
Make log macros into expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
syyyr committed Jun 13, 2024
1 parent 428aa40 commit ef44b57
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion libnecrolog/necrolog.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "necrolog.h"

#include <array>
#include <ctime>
#include <algorithm>
#include <array>
#include <filesystem>
#include <iostream>

Expand Down
10 changes: 6 additions & 4 deletions libnecrolog/necrolog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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("")
Expand Down

0 comments on commit ef44b57

Please sign in to comment.