Skip to content

Commit

Permalink
logger: simplify debug log function name
Browse files Browse the repository at this point in the history
  • Loading branch information
ken-matsui committed Nov 17, 2024
1 parent 3e1b731 commit 8d01ea9
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/Logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,27 @@ enum class Level : uint8_t {
Trace = 5, // -vv
};

// FIXME: duplicate code in Rustify/Tests.hpp but don't want to include it here.
// Maybe wait for modules to be stable?
constexpr std::string_view
prettifyFuncName(std::string_view func) noexcept {
if (func.empty()) {
return func;
}

const size_t end = func.find_last_of('(');
if (end == std::string_view::npos) {
return func;
}
func = func.substr(0, end);

const size_t start = func.find_last_of(' ');
if (start == std::string_view::npos) {
return func;
}
return func.substr(start + 1);
}

template <typename Fn>
concept HeadProcessor = std::is_nothrow_invocable_v<Fn, std::string_view>
&& Display<std::invoke_result_t<Fn, std::string_view>>;
Expand Down Expand Up @@ -118,7 +139,8 @@ class Logger {
level,
[lvlStr](const std::string_view func) noexcept {
return fmt::format(
"{}Poac {} {}{} ", gray("["), lvlStr, func, gray("]")
"{}Poac {} {}{} ", gray("["), lvlStr, prettifyFuncName(func),
gray("]")
);
},
func, fmt, std::forward<Args>(args)...
Expand Down

0 comments on commit 8d01ea9

Please sign in to comment.