mirror of
https://github.com/znc/znc.git
synced 2026-07-21 09:03:32 +02:00
Print timestamps in front of debug messages.
This commit is contained in:
+15
-1
@@ -11,6 +11,10 @@
|
|||||||
|
|
||||||
#include <znc/zncconfig.h>
|
#include <znc/zncconfig.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <ctime>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <sstream>
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
using std::cout;
|
using std::cout;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
@@ -28,7 +32,7 @@ using std::endl;
|
|||||||
*/
|
*/
|
||||||
#define DEBUG(f) do { \
|
#define DEBUG(f) do { \
|
||||||
if (CDebug::Debug()) { \
|
if (CDebug::Debug()) { \
|
||||||
cout << f << endl; \
|
cout << CDebug::GetTimestamp() << f << endl; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
@@ -38,6 +42,16 @@ public:
|
|||||||
static bool StdoutIsTTY() { return stdoutIsTTY; }
|
static bool StdoutIsTTY() { return stdoutIsTTY; }
|
||||||
static void SetDebug(bool b) { debug = b; }
|
static void SetDebug(bool b) { debug = b; }
|
||||||
static bool Debug() { return debug; }
|
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:
|
protected:
|
||||||
static bool stdoutIsTTY;
|
static bool stdoutIsTTY;
|
||||||
|
|||||||
Reference in New Issue
Block a user