Show filename in debuglog instead of function.

This commit is contained in:
tastytea 2020-01-05 20:11:42 +01:00
parent b8802d3674
commit b93fe57cae
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
1 changed files with 17 additions and 1 deletions

View File

@ -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