From 0f739de2c083bf19c7e4ee080390a4840ccecbee Mon Sep 17 00:00:00 2001 From: HaleBob Date: Sun, 20 Nov 2011 23:14:47 +0100 Subject: [PATCH] Print timestamps in front of debug messages. --- include/znc/ZNCDebug.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/include/znc/ZNCDebug.h b/include/znc/ZNCDebug.h index ceb200f4..158950f9 100644 --- a/include/znc/ZNCDebug.h +++ b/include/znc/ZNCDebug.h @@ -11,6 +11,10 @@ #include #include +#include +#include +#include +#include using std::cout; using std::endl; @@ -28,7 +32,7 @@ using std::endl; */ #define DEBUG(f) do { \ if (CDebug::Debug()) { \ - cout << f << endl; \ + cout << CDebug::GetTimestamp() << f << endl; \ } \ } while (0) @@ -38,6 +42,16 @@ public: static bool StdoutIsTTY() { return stdoutIsTTY; } static void SetDebug(bool b) { debug = b; } static bool Debug() { return debug; } + static std::string GetTimestamp() { + char buf[64]; + timeval time_now; + gettimeofday(&time_now, NULL); + tm* time_info = localtime(&time_now.tv_sec); + strftime(buf, sizeof(buf), "[%Y-%m-%d %H:%M:%S.", time_info); + std::ostringstream buffer; + buffer << buf << std::setw(6) << std::setfill('0') << (time_now.tv_usec) << "]: "; + return buffer.str(); + } protected: static bool stdoutIsTTY;