Skip to content

Commit

Permalink
Adding LogScopeIndent macro
Browse files Browse the repository at this point in the history
  • Loading branch information
nadrino committed Apr 14, 2023
1 parent 9bdda8b commit 7bc58b8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 5 additions & 4 deletions include/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#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 Down Expand Up @@ -223,10 +225,9 @@ namespace {
#endif

public:
class Indent{
public:
inline Indent(){ Logger::setIndentStr(Logger::getIndentStr() + " "); }
inline ~Indent(){ Logger::setIndentStr(Logger::getIndentStr().substr(0, Logger::getIndentStr().size()-2)); }
struct ScopedIndent{
inline ScopedIndent(){ Logger::setIndentStr(Logger::getIndentStr() + " "); }
inline ~ScopedIndent(){ Logger::setIndentStr(Logger::getIndentStr().substr(0, Logger::getIndentStr().size()-2)); }
};

};
Expand Down
5 changes: 5 additions & 0 deletions include/implementation/LoggerUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
#define HAS_CPP_11 (__cplusplus >= 201103L)
#endif // HAS_CPP_11


#define CAT_(a, b) a ## b
#define CAT(a, b) CAT_(a, b)
#define MAKE_VARNAME_LINE(Var) CAT(Var, __LINE__)

// Header
namespace LoggerUtils{

Expand Down

0 comments on commit 7bc58b8

Please sign in to comment.