From e2ae567b9fe144ab1ba53f947123653767577bfc Mon Sep 17 00:00:00 2001 From: WerWolv Date: Wed, 20 Dec 2023 15:10:53 +0100 Subject: [PATCH] fix: Logger not printing project prefix properly --- lib/libimhex/include/hex/helpers/logger.hpp | 4 ++-- lib/libimhex/source/helpers/logger.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/libimhex/include/hex/helpers/logger.hpp b/lib/libimhex/include/hex/helpers/logger.hpp index ef056928b..0338bb9f6 100644 --- a/lib/libimhex/include/hex/helpers/logger.hpp +++ b/lib/libimhex/include/hex/helpers/logger.hpp @@ -29,13 +29,13 @@ namespace hex::log { std::vector& getLogEntries(); - [[maybe_unused]] void printPrefix(FILE *dest, const fmt::text_style &ts, const std::string &level); + [[maybe_unused]] void printPrefix(FILE *dest, const fmt::text_style &ts, const std::string &level, const char *projectName); [[maybe_unused]] void print(const fmt::text_style &ts, const std::string &level, const std::string &fmt, auto && ... args) { std::scoped_lock lock(impl::g_loggerMutex); auto dest = impl::getDestination(); - printPrefix(dest, ts, level); + printPrefix(dest, ts, level, IMHEX_PROJECT_NAME); auto message = fmt::format(fmt::runtime(fmt), args...); fmt::print(dest, "{}\n", message); diff --git a/lib/libimhex/source/helpers/logger.cpp b/lib/libimhex/source/helpers/logger.cpp index e870034e4..1356a01d0 100644 --- a/lib/libimhex/source/helpers/logger.cpp +++ b/lib/libimhex/source/helpers/logger.cpp @@ -62,7 +62,7 @@ namespace hex::log::impl { return logEntries; } - void printPrefix(FILE *dest, const fmt::text_style &ts, const std::string &level) { + void printPrefix(FILE *dest, const fmt::text_style &ts, const std::string &level, const char *projectName) { const auto now = fmt::localtime(std::chrono::system_clock::to_time_t(std::chrono::system_clock::now())); fmt::print(dest, "[{0:%H:%M:%S}] ", now); @@ -72,10 +72,10 @@ namespace hex::log::impl { else fmt::print(dest, ts, "{0} ", level); - fmt::print(dest, "[{0}] ", IMHEX_PROJECT_NAME); + fmt::print(dest, "[{0}] ", projectName); - constexpr static auto ProjectNameLength = std::char_traits::length(IMHEX_PROJECT_NAME); - fmt::print(dest, "{}", std::string(ProjectNameLength > 10 ? 0 : 10 - ProjectNameLength, ' ')); + auto projectNameLength = std::string_view(projectName).length(); + fmt::print(dest, "{}", std::string(projectNameLength > 10 ? 0 : 10 - projectNameLength, ' ')); } void assertionHandler(bool expr, const char* exprString, const char* file, int line) {