diff --git a/src/celutil/debug.cpp b/src/celutil/debug.cpp index fe323fc1..7cdf2e11 100644 --- a/src/celutil/debug.cpp +++ b/src/celutil/debug.cpp @@ -7,44 +7,7 @@ // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. -#ifdef _MSC_VER -#include -#endif -#include -#include -#include -#include - -static int debugVerbosity = 0; - -#if defined(DEBUG) || defined(_DEBUG) -void DebugPrint(int level, const char *format, ...) -{ - va_list args; - va_start(args, format); - - if (level <= debugVerbosity) - { -#ifdef _MSC_VER - if (IsDebuggerPresent()) - { - char buf[1024]; - fmt::vsprintf(buf, format, args); - OutputDebugStringA(buf); - } - else - { - fmt::vfprintf(stdout, format, args); - } -#else - fmt::vfprintf(stderr, format, args); -#endif - } - - va_end(args); -} -#endif /* DEBUG */ - +int debugVerbosity = 0; void SetDebugVerbosity(int dv) { diff --git a/src/celutil/debug.h b/src/celutil/debug.h index 631d42c1..c5144747 100644 --- a/src/celutil/debug.h +++ b/src/celutil/debug.h @@ -10,31 +10,40 @@ #ifndef _DEBUG_H_ #define _DEBUG_H_ -// Define the DPRINTF macro; g++ supports macros with variable -// length arguments, so we'll use those when we can. +#ifdef _MSC_VER +#include +#endif +#include +#include + #ifdef DPRINTF #undef DPRINTF // OSX has DPRINTF #endif // DPRINTF -#ifdef __GNUC__ - #if !defined(_DEBUG) && !defined(DEBUG) -#define DPRINTF(level, args...) +#define DPRINTF(level, format, ...) #else -#define DPRINTF(level, args...) DebugPrint(level, args) -extern void DebugPrint(int level, const char *format, ...); +extern int debugVerbosity; +template +void DPRINTF(int level, const char *format, const T & ... args) +{ + if (level <= debugVerbosity) + { +#ifdef _MSC_VER + if (IsDebuggerPresent()) + { + OutputDebugStringA(fmt::sprintf(format, args...).c_str()); + } + else + { + fmt::fprintf(std::cerr, format, args...); + } +#else + fmt::fprintf(std::cerr, format, args...); #endif - -#else - -#if !defined(_DEBUG) && !defined(DEBUG) -#define DPRINTF // -#else -#define DPRINTF DebugPrint -extern void DebugPrint(int level, const char *format, ...); -#endif - -#endif // __GNUC__ + } +} +#endif /* DEBUG */ extern void SetDebugVerbosity(int); extern int GetDebugVerbosity();