From 593e07539984ba66b83dec7ad02455492117a1d9 Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Fri, 21 Sep 2018 16:28:07 +0200 Subject: [PATCH] utility: don't process log messages in stream macros when logging disabled --- src/lib/utility/logging/logging.h | 54 ++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/src/lib/utility/logging/logging.h b/src/lib/utility/logging/logging.h index 93507d45..894dfd87 100644 --- a/src/lib/utility/logging/logging.h +++ b/src/lib/utility/logging/logging.h @@ -53,54 +53,72 @@ #define LOG_INFO_STREAM(__s__) \ do \ { \ - std::stringstream __ss__; \ - __ss__ __s__; \ - LogManager::getInstance()->logInfo(__ss__.str(), __FILE__, __FUNCTION__, __LINE__); \ + if (LogManager::getInstance()->getLoggingEnabled()) \ + { \ + std::stringstream __ss__; \ + __ss__ __s__; \ + LogManager::getInstance()->logInfo(__ss__.str(), __FILE__, __FUNCTION__, __LINE__); \ + } \ } \ while(0) #define LOG_WARNING_STREAM(__s__) \ do \ { \ - std::stringstream __ss__; \ - __ss__ __s__; \ - LogManager::getInstance()->logWarning(__ss__.str(), __FILE__, __FUNCTION__, __LINE__); \ + if (LogManager::getInstance()->getLoggingEnabled()) \ + { \ + std::stringstream __ss__; \ + __ss__ __s__; \ + LogManager::getInstance()->logWarning(__ss__.str(), __FILE__, __FUNCTION__, __LINE__); \ + } \ } \ while(0) #define LOG_ERROR_STREAM(__s__) \ do \ { \ - std::stringstream __ss__; \ - __ss__ __s__; \ - LogManager::getInstance()->logError(__ss__.str(), __FILE__, __FUNCTION__, __LINE__); \ + if (LogManager::getInstance()->getLoggingEnabled()) \ + { \ + std::stringstream __ss__; \ + __ss__ __s__; \ + LogManager::getInstance()->logError(__ss__.str(), __FILE__, __FUNCTION__, __LINE__); \ + } \ } \ while(0) #define LOG_INFO_STREAM_BARE(__s__) \ do \ { \ - std::stringstream __ss__; \ - __ss__ __s__; \ - LogManager::getInstance()->logInfo(__ss__.str(), "", "", 0); \ + if (LogManager::getInstance()->getLoggingEnabled()) \ + { \ + std::stringstream __ss__; \ + __ss__ __s__; \ + LogManager::getInstance()->logInfo(__ss__.str(), "", "", 0); \ + } \ } \ while(0) #define LOG_WARNING_STREAM_BARE(__s__) \ do \ { \ - std::stringstream __ss__; \ - __ss__ __s__; \ - LogManager::getInstance()->logWarning(__ss__.str(), "", "", 0); \ + if (LogManager::getInstance()->getLoggingEnabled()) \ + { \ + std::stringstream __ss__; \ + __ss__ __s__; \ + LogManager::getInstance()->logWarning(__ss__.str(), "", "", 0); \ + } \ } \ while(0) #define LOG_ERROR_STREAM_BARE(__s__) \ do \ { \ - std::stringstream __ss__; \ - __ss__ __s__; \ - LogManager::getInstance()->logError(__ss__.str(), "", "", 0); \ + if (LogManager::getInstance()->getLoggingEnabled()) \ + { \ + std::stringstream __ss__; \ + __ss__ __s__; \ + LogManager::getInstance()->logError(__ss__.str(), "", "", 0); \ + } \ } \ while(0)