From b93fe57caec7d87764d60dc36b69e8f7aa01bcaa Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 5 Jan 2020 20:11:42 +0100 Subject: Show filename in debuglog instead of function. --- src/log.hpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/log.hpp b/src/log.hpp index 5bdcc96..43d4fc4 100644 --- a/src/log.hpp +++ b/src/log.hpp @@ -18,14 +18,30 @@ #define MASTODONPP_LOG_HPP #include +#include namespace mastodonpp { using std::cerr; +using std::string_view; + +constexpr auto shorten_filename(const string_view &filename) +{ + for (const string_view &dir : {"/src/", "/include/"}) + { + auto pos{filename.rfind("/src/")}; + if (pos != string_view::npos) + { + return filename.substr(pos + dir.size()); + } + } + return filename; +} #ifndef NDEBUG - #define debuglog cerr << "[" << __func__ << "():" << __LINE__ << "] DEBUG: " +#define debuglog cerr << "[" << shorten_filename(__FILE__) \ + << ':' << __LINE__ << "] DEBUG: " #else #define debuglog false && cerr #endif -- cgit v1.2.3-54-g00ecf