Commit 7e210d68 authored by Oliver Heidmann's avatar Oliver Heidmann
Browse files

added context to debug output

parent 7efb6fe4
......@@ -9,15 +9,14 @@ bool verbose = false;
bool pedantic = false;
bool exitOnError = true;
int DebugLevel = 0;
void
Debug_(const char *p_func, int p_debugScope, std::function<void()> p_function)
Debug_(const char *p_func,const char* context, int p_debugScope, std::function<void()> p_function)
{
(void) p_func;
if (p_debugScope) p_function();
}
void
Debug_(const char *p_func, std::function<void()> p_function)
Debug_(const char *p_func,const char* context, std::function<void()> p_function)
{
(void) p_func;
if (DebugLevel > 0) p_function();
......
......@@ -76,30 +76,31 @@ get_padding(const char *p_func)
return std::string(padding_width - len, ' ');
}
void Debug_(const char *p_func, int p_debugScope, std::function<void()> p_function);
void Debug_(const char *p_func, std::function<void()> p_function);
void Debug_(const char *p_func, const char *context, int p_debugScope, std::function<void()> p_function);
void Debug_(const char *p_func, const char *context, std::function<void()> p_function);
template <typename... Args>
void
Debug_(const char *p_func, int p_debugScope, const std::string &format, Args const &... args)
Debug_(const char *p_func, const char *context, int p_debugScope, const std::string &format, Args const &... args)
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
#pragma GCC diagnostic ignored "-Wformat-security"
if (p_debugScope)
fprintf(stderr, (Cyan("deb: ") + std::string(p_func) + get_padding(p_func) + format + "\n").c_str(), Argument(args)...);
fprintf(stderr, (Cyan(context) + ": " + std::string(p_func) + get_padding(p_func) + format + "\n").c_str(), Argument(args)...);
#pragma GCC diagnostic pop
}
template <typename... Args>
void
Debug_(const char *p_func, const std::string &format, Args const &... args)
Debug_(const char *p_func, const char *context, const std::string &format, Args const &... args)
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
#pragma GCC diagnostic ignored "-Wformat-security"
if (DebugLevel)
fprintf(stderr, (Cyan("deb: ") + std::string(p_func) + get_padding(p_func) + format + "\n").c_str(), Argument(args)...);
fprintf(stderr, (Cyan(context) + ": " + std::string(p_func) + get_padding(p_func) + format + "\n").c_str(), Argument(args)...);
#pragma GCC diagnostic pop
}
......@@ -157,7 +158,7 @@ SysError_(const char * func, const std::string &format, Args const &... args) no
#define Verbose(...) Verbose_(__VA_ARGS__)
#ifndef NO_DEBUG
#define Debug(...) MpMO::Debug_(__func__, __VA_ARGS__)
#define Debug(...) MpMO::Debug_(__func__, CdoOut::getContext(), __VA_ARGS__)
#else
#define Debug(...)
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment