From 366189e4477a971dbe11c180154b36792d2fd38a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wolfgang=20M=C3=BCller?= Date: Sat, 12 Jan 2019 19:14:28 +0100 Subject: [PATCH] logger: resolve level string in msgWithTime This means that the log level string is included in logs to files and stdout even if syslog output is enabled. --- src/common/logger.cpp | 47 ++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/src/common/logger.cpp b/src/common/logger.cpp index 2c601fdb..031aa5e0 100644 --- a/src/common/logger.cpp +++ b/src/common/logger.cpp @@ -37,7 +37,27 @@ namespace { QByteArray msgWithTime(const Logger::LogEntry& msg) { - return (msg.timeStamp.toString("yyyy-MM-dd hh:mm:ss ") + msg.message + "\n").toUtf8(); + 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(); } } // namespace @@ -151,31 +171,8 @@ void Logger::handleMessage(QtMsgType type, const QString& msg) void Logger::handleMessage(LogLevel level, const QString& msg) { - QString logString; - - // Only add the log level to the message if we do not output to syslog - if (!_syslogEnabled) { - switch (level) { - case LogLevel::Debug: - logString = "[Debug] "; - break; - case LogLevel::Info: - logString = "[Info ] "; - break; - case LogLevel::Warning: - logString = "[Warn ] "; - break; - case LogLevel::Error: - logString = "[Error] "; - break; - case LogLevel::Fatal: - logString = "[FATAL] "; - break; - } - } - // Use signal connection to make this method thread-safe - emit messageLogged({QDateTime::currentDateTime(), level, logString += msg}); + emit messageLogged({QDateTime::currentDateTime(), level, msg}); } void Logger::onMessageLogged(const LogEntry& message) -- 2.20.1