From: Shane Synan Date: Thu, 14 Feb 2019 00:31:50 +0000 (-0500) Subject: logger: Dedup code, fix client Debug Log loglevel X-Git-Tag: 0.13.1~5 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=3c910a417a72dfa529ad514d9a616139b7d57bab logger: Dedup code, fix client Debug Log loglevel Deduplicate code by moving LogEntry formatting into a separate function, LogEntry::toString(), which applies timestamps and the log level string. Fix client Debug Log dialog to print log level using this new function. Modify msgWithTime() to use this new function, too. --- diff --git a/src/common/logger.cpp b/src/common/logger.cpp index 80920720..72cfa50b 100644 --- a/src/common/logger.cpp +++ b/src/common/logger.cpp @@ -36,27 +36,7 @@ namespace { QByteArray msgWithTime(const Logger::LogEntry &msg) { - QString levelString; - - switch (msg.logLevel) { - case Logger::LogLevel::Debug: - levelString = "[Debug] "; - break; - case Logger::LogLevel::Info: - levelString = "[Info ] "; - break; - case Logger::LogLevel::Warning: - levelString = "[Warn ] "; - break; - case Logger::LogLevel::Error: - levelString = "[Error] "; - break; - case Logger::LogLevel::Fatal: - levelString = "[FATAL] "; - break; - } - - return (msg.timeStamp.toString("yyyy-MM-dd hh:mm:ss ") + levelString + msg.message + "\n").toUtf8(); + return (msg.toString() + "\n").toUtf8(); }; } @@ -266,3 +246,29 @@ void Logger::outputMessage(const LogEntry &message) #endif } + + +QString Logger::LogEntry::toString() const +{ + QString levelString; + + switch (logLevel) { + case Logger::LogLevel::Debug: + levelString = "[Debug] "; + break; + case Logger::LogLevel::Info: + levelString = "[Info ] "; + break; + case Logger::LogLevel::Warning: + levelString = "[Warn ] "; + break; + case Logger::LogLevel::Error: + levelString = "[Error] "; + break; + case Logger::LogLevel::Fatal: + levelString = "[FATAL] "; + break; + } + + return timeStamp.toString("yyyy-MM-dd hh:mm:ss ") + levelString + message; +} diff --git a/src/common/logger.h b/src/common/logger.h index af8fa3af..1f11e46e 100644 --- a/src/common/logger.h +++ b/src/common/logger.h @@ -51,6 +51,13 @@ public: QDateTime timeStamp; LogLevel logLevel; QString message; + + /** + * Gets this log entry in a printable format, with timestamp and log level + * + * @return the log entry, formatted with timestamp and log level + */ + QString toString() const; }; /** diff --git a/src/qtui/debuglogdlg.cpp b/src/qtui/debuglogdlg.cpp index 130ad7d3..73391ce3 100644 --- a/src/qtui/debuglogdlg.cpp +++ b/src/qtui/debuglogdlg.cpp @@ -43,7 +43,7 @@ DebugLogDlg::DebugLogDlg(QWidget *parent) QString DebugLogDlg::toString(const Logger::LogEntry &msg) { - return msg.timeStamp.toString("yyyy-MM-dd hh:mm:ss ") + msg.message + "\n"; + return msg.toString() + "\n"; }