From 7bc58b8ffdb9291ff11a0a741edef1521d3a03c9 Mon Sep 17 00:00:00 2001 From: Adrien Blanchet Date: Fri, 14 Apr 2023 14:49:39 +0200 Subject: [PATCH] Adding LogScopeIndent macro --- include/Logger.h | 9 +++++---- include/implementation/LoggerUtils.h | 5 +++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/Logger.h b/include/Logger.h index 77b5acd..ec069ed 100644 --- a/include/Logger.h +++ b/include/Logger.h @@ -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_) @@ -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)); } }; }; diff --git a/include/implementation/LoggerUtils.h b/include/implementation/LoggerUtils.h index 0227682..b59f509 100644 --- a/include/implementation/LoggerUtils.h +++ b/include/implementation/LoggerUtils.h @@ -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{