diff --git a/include/Logger.h b/include/Logger.h index e36e200..4a8ec69 100644 --- a/include/Logger.h +++ b/include/Logger.h @@ -51,10 +51,10 @@ namespace { // Keep in mind that every parameter you set will be applied only in the context of the source file you're in // It is an inherent feature as a **header-only** library static void setMaxLogLevel(int maxLogLevel_); - static void setMaxLogLevel(LogLevel maxLogLevel_); + static void setMaxLogLevel(const LogLevel &maxLogLevel_); static void setEnableColors(bool enableColors_); static void setPropagateColorsOnUserHeader(bool propagateColorsOnUserHeader_); - static void setPrefixLevel(PrefixLevel prefixLevel_); + static void setPrefixLevel(const PrefixLevel &prefixLevel_); static void setUserHeaderStr(const std::string &userHeaderStr_); static void setPrefixFormat(const std::string &prefixFormat_); @@ -77,13 +77,13 @@ namespace { // Macro-Related Methods // Those intended to be called using the above preprocessor macros - Logger(LogLevel logLevel_, char const * fileName_, int lineNumber_); + Logger(const LogLevel &logLevel_, char const * fileName_, const int &lineNumber_); virtual ~Logger(); protected: static void buildCurrentPrefix(); - static void getFormattedUserHeaderStr(std::string &formattedUserHeaderBuffer_); + static void formatUserHeaderStr(std::string &strBuffer_); static void hookStreamBuffer(); static std::string getLogLevelColorStr(const LogLevel &selectedLogLevel_); diff --git a/include/implementation/Logger.impl.h b/include/implementation/Logger.impl.h index 599dc2d..28fa139 100644 --- a/include/implementation/Logger.impl.h +++ b/include/implementation/Logger.impl.h @@ -28,7 +28,7 @@ namespace { void Logger::setMaxLogLevel(int maxLogLevel_) { Logger::setMaxLogLevel(static_cast(maxLogLevel_)); } - void Logger::setMaxLogLevel(LogLevel maxLogLevel_) { + void Logger::setMaxLogLevel(const LogLevel &maxLogLevel_) { _maxLogLevel_ = maxLogLevel_; } void Logger::setEnableColors(bool enableColors_) { @@ -37,7 +37,7 @@ namespace { void Logger::setPropagateColorsOnUserHeader(bool propagateColorsOnUserHeader_) { _propagateColorsOnUserHeader_ = propagateColorsOnUserHeader_; } - void Logger::setPrefixLevel(PrefixLevel prefixLevel_) { + void Logger::setPrefixLevel(const PrefixLevel &prefixLevel_) { _prefixLevel_ = prefixLevel_; } void Logger::setUserHeaderStr(const std::string &userHeaderStr_) { @@ -70,7 +70,7 @@ namespace { } // C-tor D-tor - Logger::Logger(LogLevel logLevel_, char const *fileName_, int lineNumber_) { + Logger::Logger(const LogLevel &logLevel_, char const *fileName_, const int &lineNumber_) { hookStreamBuffer(); // hook the stream buffer to an object we can handle if (logLevel_ != _currentLogLevel_) _isNewLine_ = true; // force reprinting the prefix if the verbosity has changed @@ -92,14 +92,11 @@ namespace { if (_currentLogLevel_ > _maxLogLevel_) return; - { // guard -// std::lock_guard guard(_loggerMutex_); - printFormat(fmt_str, std::forward(args)...); - if (not _disablePrintfLineJump_ and fmt_str[strlen(fmt_str) - 1] != '\n') { + Logger::printFormat(fmt_str, std::forward(args)...); + if (not _disablePrintfLineJump_ and fmt_str[strlen(fmt_str) - 1] != '\n') { _outputStream_ << std::endl; _isNewLine_ = true; } - } // guard } template Logger &Logger::operator<<(const T &data) { @@ -138,7 +135,7 @@ namespace { // Nothing else -> NONE level if( Logger::_prefixLevel_ == Logger::PrefixLevel::NONE ){ if( not _userHeaderStr_.empty() ){ - Logger::getFormattedUserHeaderStr(_currentPrefix_); + Logger::formatUserHeaderStr(_currentPrefix_); _currentPrefix_ += " "; // extra space } return; @@ -197,7 +194,7 @@ namespace { // "{USER_HEADER}" -> User prefix can have doubled spaces and spaces on the left if( not _userHeaderStr_.empty() ){ strBuffer = ""; - Logger::getFormattedUserHeaderStr(strBuffer); + Logger::formatUserHeaderStr(strBuffer); LoggerUtils::replaceSubstringInsideInputString(_currentPrefix_, "{USER_HEADER}", strBuffer); } @@ -218,11 +215,11 @@ namespace { _currentPrefix_ += ": "; } } - void Logger::getFormattedUserHeaderStr(std::string &formattedUserHeaderBuffer_) { + void Logger::formatUserHeaderStr(std::string &strBuffer_) { if( not _userHeaderStr_.empty() ){ - if(_enableColors_ and _propagateColorsOnUserHeader_) formattedUserHeaderBuffer_ += getLogLevelColorStr(_currentLogLevel_); - formattedUserHeaderBuffer_ += _userHeaderStr_; - if(_enableColors_ and _propagateColorsOnUserHeader_) formattedUserHeaderBuffer_ += "\033[0m"; + if(_enableColors_ and _propagateColorsOnUserHeader_) strBuffer_ += getLogLevelColorStr(_currentLogLevel_); + strBuffer_ += _userHeaderStr_; + if(_enableColors_ and _propagateColorsOnUserHeader_) strBuffer_ += "\033[0m"; } } std::string Logger::getLogLevelColorStr(const LogLevel &selectedLogLevel_) { diff --git a/include/implementation/LoggerUtils.h b/include/implementation/LoggerUtils.h index 62d3027..64afeb6 100644 --- a/include/implementation/LoggerUtils.h +++ b/include/implementation/LoggerUtils.h @@ -70,17 +70,17 @@ namespace LoggerUtils{ }; //! String Utils - inline bool doesStringContainsSubstring(std::string string_, std::string substring_, bool ignoreCase_ = false); - inline std::string padString(const std::string& inputStr_, unsigned int padSize_, const char& padChar = ' '); + inline bool doesStringContainsSubstring(const std::string &string_, const std::string &substring_, bool ignoreCase_ = false); + inline std::string padString(const std::string& inputStr_, const unsigned int &padSize_, const char& padChar = ' '); inline std::string toLowerCase(const std::string &inputStr_); inline std::string stripStringUnicode(const std::string &inputStr_); inline std::string repeatString(const std::string &inputStr_, int amount_); - inline void replaceSubstringInsideInputString(std::string &input_str_, const std::string &substr_to_look_for_, const std::string &substr_to_replace_); inline std::vector splitString(const std::string& input_string_, const std::string& delimiter_); inline std::string formatString( const std::string& strToFormat_ ); // 0 args overrider template inline std::string formatString( const std::string& strToFormat_, const Args& ... args ); inline void removeRepeatedCharInsideInputStr(std::string &inputStr_, const std::string &doubledChar_); + inline void replaceSubstringInsideInputString(std::string &input_str_, const std::string &substr_to_look_for_, const std::string &substr_to_replace_); // Hardware Utils inline int getTerminalWidth(); @@ -91,16 +91,19 @@ namespace LoggerUtils{ namespace LoggerUtils{ // String Utils - inline bool doesStringContainsSubstring(std::string string_, std::string substring_, bool ignoreCase_){ + inline bool doesStringContainsSubstring(const std::string &string_, const std::string &substring_, bool ignoreCase_){ if(substring_.size() > string_.size()) return false; if(ignoreCase_){ - string_ = toLowerCase(string_); - substring_ = toLowerCase(substring_); + if(toLowerCase(string_).find(toLowerCase(substring_)) != std::string::npos){ + return true; + } + } + else if(string_.find(substring_) != std::string::npos){ + return true; } - if(string_.find(substring_) != std::string::npos) return true; - else return false; + return false; } - inline std::string padString(const std::string& inputStr_, unsigned int padSize_, const char& padChar){ + inline std::string padString(const std::string& inputStr_, const unsigned int &padSize_, const char& padChar){ std::string outputString; int padDelta = int(inputStr_.size()) - int(padSize_); while( padDelta < 0 ){