From 936af23bacc216bdf5cd5912728907b03eca0707 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Sun, 24 Feb 2013 21:09:54 +0100 Subject: Added Debug class for more convenient debugging output Inspired by the QDebug class and qDebug() function from Qt. Actually it might be nice if the LOG macro would also use this. --- src/utils/logger.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/utils/logger.h b/src/utils/logger.h index 65846be5..c9ca9d80 100644 --- a/src/utils/logger.h +++ b/src/utils/logger.h @@ -24,6 +24,7 @@ #include #include +#include namespace utils { @@ -192,6 +193,32 @@ class Logger static void switchLogs(); }; +/** + * Class for temporarily debugging things that are actually not interesting + * to include in the log. + * + * It is used for automatically ending with a newline, putting spaces in + * between different parameters and quoting strings. + */ +class Debug +{ +public: + ~Debug() { std::cout << std::endl; } + + template + Debug &operator << (T t) + { + std::cout << t << " "; + return *this; + } +}; + +template <> +inline Debug &Debug::operator << (const std::string &t) +{ + std::cout << "\"" << t << "\" "; + return *this; +} } // namespace utils @@ -210,4 +237,11 @@ class Logger #define LOG_ERROR(msg) LOG(Error, msg) #define LOG_FATAL(msg) LOG(Fatal, msg) +/** + * Returns an instance of the debug class for printing out a line. + * + * Usage: debug() << "testing" << a << b; + */ +inline ::utils::Debug debug() { return ::utils::Debug(); } + #endif // LOGGER_H -- cgit v1.2.3-70-g09d2