From 260a7337d36eb83f0f8c50a8d35daa9426ba1c40 Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Mon, 6 Jul 2015 15:50:21 -0700 Subject: [PATCH] Added timestamp in log #4845 --- src/gui/src/MainWindow.cpp | 12 +++++++++--- src/gui/src/MainWindow.h | 1 + src/lib/base/Log.cpp | 7 ++++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index 3811a06d..499e6af6 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -370,18 +370,18 @@ void MainWindow::updateFound(const QString &version) void MainWindow::appendLogInfo(const QString& text) { - appendLogRaw("INFO: " + text); + appendLogRaw(getTimeStamp() + " INFO: " + text); } void MainWindow::appendLogDebug(const QString& text) { if (appConfig().logLevel() >= 1) { - appendLogRaw("DEBUG: " + text); + appendLogRaw(getTimeStamp() + " DEBUG: " + text); } } void MainWindow::appendLogError(const QString& text) { - appendLogRaw("ERROR: " + text); + appendLogRaw(getTimeStamp() + " ERROR: " + text); } void MainWindow::appendLogRaw(const QString& text) @@ -492,6 +492,12 @@ bool MainWindow::autoHide() return false; } +QString MainWindow::getTimeStamp() +{ + QDateTime current = QDateTime::currentDateTime(); + return '[' + current.toString(Qt::ISODate) + ']'; +} + void MainWindow::clearLog() { m_pLogOutput->clear(); diff --git a/src/gui/src/MainWindow.h b/src/gui/src/MainWindow.h index bb0bd35d..fd3547a4 100644 --- a/src/gui/src/MainWindow.h +++ b/src/gui/src/MainWindow.h @@ -174,6 +174,7 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase void checkFingerprint(const QString& line); void checkTransmission(const QString& line); bool autoHide(); + QString getTimeStamp(); private: QSettings& m_Settings; diff --git a/src/lib/base/Log.cpp b/src/lib/base/Log.cpp index a7bede73..5c66020e 100644 --- a/src/lib/base/Log.cpp +++ b/src/lib/base/Log.cpp @@ -174,16 +174,17 @@ Log::print(const char* file, int line, const char* fmt, ...) char message[kLogMessageLength]; -#ifndef NDEBUG struct tm *tm; char tmp[220]; time_t t; time(&t); tm = localtime(&t); sprintf(tmp, "%04i-%02i-%02iT%02i:%02i:%02i", tm->tm_year + 1900, tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); - sprintf(message, "%s %s: %s\n\t%s,%d", tmp, g_priority[priority], buffer, file, line); + +#ifndef NDEBUG + sprintf(message, "[%s] %s: %s\n\t%s,%d", tmp, g_priority[priority], buffer, file, line); #else - sprintf(message, "%s: %s", g_priority[priority], buffer); + sprintf(message, "[%s] %s: %s", tmp, g_priority[priority], buffer); #endif output(priority, message);