mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01:00
Print timestamps in front of debug messages.
This commit is contained in:
@@ -11,6 +11,10 @@
|
||||
|
||||
#include <znc/zncconfig.h>
|
||||
#include <iostream>
|
||||
#include <ctime>
|
||||
#include <sys/time.h>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user