Skip to content

Commit

Permalink
adding LogIf macros
Browse files Browse the repository at this point in the history
  • Loading branch information
nadrino committed Apr 17, 2023
1 parent 7bc58b8 commit e25459b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
18 changes: 12 additions & 6 deletions include/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
#include <unordered_set>


#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__})
Expand All @@ -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})
Expand All @@ -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_)
Expand All @@ -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 )

Expand Down
5 changes: 5 additions & 0 deletions include/implementation/LoggerUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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{

Expand Down

0 comments on commit e25459b

Please sign in to comment.