diff options
author | tastytea | 2020-01-05 20:11:42 +0100 |
---|---|---|
committer | tastytea | 2020-01-05 20:19:59 +0100 |
commit | b93fe57caec7d87764d60dc36b69e8f7aa01bcaa (patch) | |
tree | ada51f12a264c4107ee24ee919fad0bb6c73524d | |
parent | b8802d36747280afd33a428afa758972c662ae29 (diff) | |
download | mastodonpp-b93fe57caec7d87764d60dc36b69e8f7aa01bcaa.tar mastodonpp-b93fe57caec7d87764d60dc36b69e8f7aa01bcaa.tar.gz mastodonpp-b93fe57caec7d87764d60dc36b69e8f7aa01bcaa.zip |
Show filename in debuglog instead of function.
-rw-r--r-- | src/log.hpp | 18 |
1 files changed, 17 insertions, 1 deletions
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 <iostream> +#include <string_view> 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 |