From e25459b48a90f239ab70597bb415fbbad65fe301 Mon Sep 17 00:00:00 2001 From: Adrien Blanchet Date: Mon, 17 Apr 2023 17:06:12 +0200 Subject: [PATCH] adding LogIf macros --- include/Logger.h | 18 ++++++++++++------ include/implementation/LoggerUtils.h | 5 +++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/include/Logger.h b/include/Logger.h index ec069ed..cfb6f46 100644 --- a/include/Logger.h +++ b/include/Logger.h @@ -18,9 +18,6 @@ #include -#define GET_OVERLOADED_MACRO2(_1,_2,NAME,...) NAME -#define GET_OVERLOADED_MACRO3(_1,_2,_3,NAME,...) NAME - // Here is what you want to use #define LogFatal (Logger{Logger::LogLevel::FATAL, FILENAME, __LINE__}) #define LogError (Logger{Logger::LogLevel::ERROR, FILENAME, __LINE__}) @@ -30,7 +27,16 @@ #define LogDebug (Logger{Logger::LogLevel::DEBUG, FILENAME, __LINE__}) #define LogTrace (Logger{Logger::LogLevel::TRACE, FILENAME, __LINE__}) -// dev +// conditional +#define LogFatalIf(isPrint_) (isPrint_ ? LogFatal : LogInvalid) +#define LogErrorIf(isPrint_) (isPrint_ ? LogError : LogInvalid) +#define LogAlertIf(isPrint_) (isPrint_ ? LogAlert : LogInvalid) +#define LogWarningIf(isPrint_) (isPrint_ ? LogWarning : LogInvalid) +#define LogInfoIf(isPrint_) (isPrint_ ? LogInfo : LogInvalid) +#define LogDebugIf(isPrint_) (isPrint_ ? LogDebug : LogInvalid) +#define LogTraceIf(isPrint_) (isPrint_ ? LogTrace : LogInvalid) + +// once #define LogFatalOnce (Logger{Logger::LogLevel::FATAL, FILENAME, __LINE__, true}) #define LogErrorOnce (Logger{Logger::LogLevel::ERROR, FILENAME, __LINE__, true}) #define LogAlertOnce (Logger{Logger::LogLevel::ALERT, FILENAME, __LINE__, true}) @@ -39,8 +45,6 @@ #define LogDebugOnce (Logger{Logger::LogLevel::DEBUG, FILENAME, __LINE__, true}) #define LogTraceOnce (Logger{Logger::LogLevel::TRACE, FILENAME, __LINE__, true}) -#define LogScopeIndent Logger::ScopedIndent MAKE_VARNAME_LINE(scopeIndentTempObj); - // To make assertions #define LogThrowIf2(isThrowing_, errorMessage_) if(isThrowing_){(LogError << "(" << __PRETTY_FUNCTION__ << "): "<< errorMessage_ << std::endl).throwError(#isThrowing_);} #define LogThrowIf1(isThrowing_) LogThrowIf2(isThrowing_, #isThrowing_) @@ -59,6 +63,8 @@ #define LogReturnIf1(isReturn_) LogReturnIf2(isReturn_, (#isReturn_)) #define LogReturnIf(...) GET_OVERLOADED_MACRO3(__VA_ARGS__, LogReturnIf3, LogReturnIf2, LogReturnIf1)(__VA_ARGS__) +#define LogScopeIndent Logger::ScopedIndent MAKE_VARNAME_LINE(scopeIndentTempObj); + // To setup the logger in a given source file #define LoggerInit( lambdaInit ) LoggerInitializerImpl( lambdaInit ) diff --git a/include/implementation/LoggerUtils.h b/include/implementation/LoggerUtils.h index b59f509..e4c89cd 100644 --- a/include/implementation/LoggerUtils.h +++ b/include/implementation/LoggerUtils.h @@ -30,6 +30,11 @@ #define CAT(a, b) CAT_(a, b) #define MAKE_VARNAME_LINE(Var) CAT(Var, __LINE__) +#define LogInvalid (Logger{Logger::LogLevel::INVALID, FILENAME, __LINE__}) + +#define GET_OVERLOADED_MACRO2(_1,_2,NAME,...) NAME +#define GET_OVERLOADED_MACRO3(_1,_2,_3,NAME,...) NAME + // Header namespace LoggerUtils{