From 50e4f5b3f2385e5ad63485575f01793ae9b2af46 Mon Sep 17 00:00:00 2001 From: ptmaster Date: Sat, 30 Nov 2024 13:46:40 +0800 Subject: [PATCH] fix shrink logger function name --- src/logger.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/logger.cpp b/src/logger.cpp index f642522..898cfb5 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -1,4 +1,5 @@ #include +#include #include "logger.h" static Logger *loggerInstance = nullptr; @@ -45,14 +46,10 @@ LogMessageHandler (const char *function, const char *codeFile, int codeLine, Log // Determine log type string std::string logType = GetLogLevelString (messageLevel); - int find_idx = 0, begin = -2, end = 0; - while (function[find_idx] != 0) { - if (begin == -2 && function[find_idx] == ' ') begin = -1; - else if (begin == -1 && function[find_idx] == ' ') begin = find_idx + 1; - else if (end == 0 && ((begin > 0 && function[find_idx] == ' ') || function[find_idx] == '(')) end = find_idx; - find_idx ++; - } - std::string short_function = std::string(function + begin, end - begin); + // Shrink function name by regex + std::string short_function (function); + std::regex re(R"(.*? (([\w<>]+::)*[\w]+( [()<>+-]+)?)\(\w+.*?\))"); + short_function = std::regex_replace (short_function, re, "$1"); // Remove the absolute path of the build dir constexpr std::string_view build_dir = XSTRING (SOURCE_ROOT);