summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2013-02-24 21:09:54 +0100
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2013-02-24 21:11:06 +0100
commit936af23bacc216bdf5cd5912728907b03eca0707 (patch)
treebcd1b5066a02a264bb86b6eecfc792e497b036f6
parent802eb61090abaf245617bc136ea21303af1c71b9 (diff)
downloadmanaserv-936af23bacc216bdf5cd5912728907b03eca0707.tar.gz
manaserv-936af23bacc216bdf5cd5912728907b03eca0707.tar.bz2
manaserv-936af23bacc216bdf5cd5912728907b03eca0707.tar.xz
manaserv-936af23bacc216bdf5cd5912728907b03eca0707.zip
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.
-rw-r--r--src/utils/logger.h34
1 files changed, 34 insertions, 0 deletions
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 <iosfwd>
#include <sstream>
+#include <iostream>
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 <class T>
+ 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