Skip to content

Commit

Permalink
fix shrink logger function name
Browse files Browse the repository at this point in the history
  • Loading branch information
ryumiyax committed Nov 30, 2024
1 parent 7dc76ed commit 50e4f5b
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/logger.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <iostream>
#include <regex>
#include "logger.h"

static Logger *loggerInstance = nullptr;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 50e4f5b

Please sign in to comment.