From 7c0766791d5ef6e7cfa638838d35c0c94914d6a9 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 12 Nov 2025 08:29:55 +0100 Subject: [PATCH 1/4] Refactor Logger methods for clarity and const correctness --- code/Common/Logger.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/code/Common/Logger.cpp b/code/Common/Logger.cpp index 369cfcc..22be77f 100644 --- a/code/Common/Logger.cpp +++ b/code/Common/Logger.cpp @@ -189,8 +189,7 @@ void Logger::print(const String &msg, PrintMode mode) { } } - if (msg.size() > 8) { - if (msg[6] == '=' && msg[7] == '>') { + if (msg.size() > 8 && msg[6] == '=' && msg[7] == '>') { mIntention += 2; } } @@ -231,7 +230,7 @@ void Logger::registerLogStream(AbstractLogStream *pLogStream) { mLogStreams.add(pLogStream); } -void Logger::unregisterLogStream(AbstractLogStream *logStream) { +void Logger::unregisterLogStream(const AbstractLogStream *logStream) { if (nullptr == logStream) { return; } From 8b25a1a2a904410b4377ca5c726053ed74baa621 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 12 Nov 2025 08:32:15 +0100 Subject: [PATCH 2/4] Refactor Logger class comments and parameter types Updated comments and parameter types in Logger.h for clarity. --- include/cppcore/Common/Logger.h | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/include/cppcore/Common/Logger.h b/include/cppcore/Common/Logger.h index 8416077..bdd5e66 100644 --- a/include/cppcore/Common/Logger.h +++ b/include/cppcore/Common/Logger.h @@ -72,13 +72,11 @@ class DLL_CPPCORE_EXPORT AbstractLogStream { //------------------------------------------------------------------------------------------------- /// -/// @brief This class implements a simple logger. -/// +/// @brief This class implements a simple logger. /// The logger is implemented as a singleton. You can attach several log streams to it, which can -/// be used to log the messages to several output channels like a window or a log file or something -/// else. -/// The granularity of the logged messages can be controlled by the severity of the logger. The -/// supported modes are normal ( no debug and info messages ), verbose ( all messages will be +/// be used to log the messages to several output channels like a window or a log file or something +/// else. The granularity of the logged messages can be controlled by the severity of the logger. +/// The supported modes are normal ( no debug and info messages ), verbose ( all messages will be /// logged ) and debug ( the debug messages will be logged as well, be careful with this option ). //------------------------------------------------------------------------------------------------- class DLL_CPPCORE_EXPORT Logger final { @@ -87,8 +85,8 @@ class DLL_CPPCORE_EXPORT Logger final { enum class VerboseMode { Invalid = -1, ///< Invalid marker Normal, ///< Only warnings and errors will be logged. - Verbose, ///< Normal messages will be logged as well. - Debug, ///< All debug messages will be logged as well. + Verbose, ///< Normal messages will be logged as well. + Debug, ///< All debug messages will be logged as well. Trace, ///< Will enable the tracing. Count ///< Number of enums }; @@ -166,7 +164,7 @@ class DLL_CPPCORE_EXPORT Logger final { /// @brief Unregisters a registered log stream. /// @param[in] pLogStream A pointer showing to the log stream. - void unregisterLogStream(AbstractLogStream *pLogStream); + void unregisterLogStream(const AbstractLogStream *pLogStream); private: Logger(); From f438c5a1bb2f61885979d0e5a085dd12d4712b95 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 12 Nov 2025 08:32:52 +0100 Subject: [PATCH 3/4] Change getDateTime to a const member function --- include/cppcore/Common/Logger.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/cppcore/Common/Logger.h b/include/cppcore/Common/Logger.h index bdd5e66..94dd919 100644 --- a/include/cppcore/Common/Logger.h +++ b/include/cppcore/Common/Logger.h @@ -169,7 +169,7 @@ class DLL_CPPCORE_EXPORT Logger final { private: Logger(); ~Logger(); - String getDateTime(); + String getDateTime() const; private: // @brief The Standard log stream. From 0358aef739b63afab6c4d8cb7353decaed499284 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 12 Nov 2025 08:35:13 +0100 Subject: [PATCH 4/4] Update Logger.cpp --- code/Common/Logger.cpp | 73 +++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/code/Common/Logger.cpp b/code/Common/Logger.cpp index 22be77f..3be7b48 100644 --- a/code/Common/Logger.cpp +++ b/code/Common/Logger.cpp @@ -30,40 +30,41 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include namespace cppcore { - -static void appendDomain(const String &domain, String &logMsg) { - if (!domain.isEmpty()) { - logMsg += '('; - logMsg += domain; - logMsg += ')'; - } -} - -static ::std::string stripFilename(const ::std::string &filename) { - if (filename.empty()) { - return filename; +namespace { + void appendDomain(const String &domain, String &logMsg) { + if (!domain.isEmpty()) { + logMsg += '('; + logMsg += domain; + logMsg += ')'; + } } - - ::std::string::size_type pos = filename.find_last_of("/"); - if (pos == ::std::string::npos) { - return filename; + + ::std::string stripFilename(const ::std::string &filename) { + if (filename.empty()) { + return filename; + } + + ::std::string::size_type pos = filename.find_last_of("/"); + if (pos == ::std::string::npos) { + return filename; + } + const ::std::string strippedName = filename.substr(pos + 1, filename.size() - pos - 1); + + return strippedName; } - const ::std::string strippedName = filename.substr(pos + 1, filename.size() - pos - 1); - - return strippedName; -} - -static void addTraceInfo(const String &file, int line, String &msg) { - if (Logger::getInstance()->getVerboseMode() == Logger::VerboseMode::Trace) { - msg += String(" (", 2); - std::string stripped = stripFilename(file.c_str()); - msg += String(stripped.c_str(), stripped.size()); - msg += String(", ", 2); - std::stringstream ss; - ss << line; - std::string lineno = ss.str(); - msg += String(lineno.c_str(), lineno.size()); - msg += ')'; + + void addTraceInfo(const String &file, int line, String &msg) { + if (Logger::getInstance()->getVerboseMode() == Logger::VerboseMode::Trace) { + msg += String(" (", 2); + std::string stripped = stripFilename(file.c_str()); + msg += String(stripped.c_str(), stripped.size()); + msg += String(", ", 2); + std::stringstream ss; + ss << line; + std::string lineno = ss.str(); + msg += String(lineno.c_str(), lineno.size()); + msg += ')'; + } } } @@ -82,7 +83,7 @@ bool AbstractLogStream::isActive() const { Logger *Logger::sLogger = nullptr; Logger *Logger::create() { - if (nullptr == sLogger) { + if (sLogger == nullptr) { sLogger = new Logger; } @@ -98,7 +99,7 @@ void Logger::set(Logger *logger) { } Logger *Logger::getInstance() { - if (nullptr == sLogger) { + if (sLogger == nullptr) { static_cast(create()); } @@ -253,8 +254,8 @@ Logger::~Logger() { } } -String Logger::getDateTime() { - static const uint32_t Space = 2; +String Logger::getDateTime() const { + static constexpr uint32_t Space = 2; DateTime currentDateTime; std::stringstream stream; stream.fill('0');