X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fcommon%2Flogger.cpp;h=51f1366a24f7704a3e7dccaef82d1ace803121e8;hb=45645a28bdc5b6c1052b3e4cebf8cc80832d205a;hp=2c601fdbfedf0a9e5dd82ec77daebb1862919692;hpb=d9026a22f17d5f8b2734cbf0348ad35de5b13f0b;p=quassel.git diff --git a/src/common/logger.cpp b/src/common/logger.cpp index 2c601fdb..51f1366a 100644 --- a/src/common/logger.cpp +++ b/src/common/logger.cpp @@ -37,7 +37,7 @@ namespace { QByteArray msgWithTime(const Logger::LogEntry& msg) { - return (msg.timeStamp.toString("yyyy-MM-dd hh:mm:ss ") + msg.message + "\n").toUtf8(); + return (msg.toString() + "\n").toUtf8(); } } // namespace @@ -107,9 +107,22 @@ void Logger::setup(bool keepMessages) #ifdef HAVE_SYSLOG _syslogEnabled = Quassel::isOptionSet("syslog"); + Quassel::RunMode mode = Quassel::runMode(); + Quassel::BuildInfo info = Quassel::buildInfo(); + QString prgname = info.applicationName; + + if (mode == Quassel::RunMode::ClientOnly) { + prgname = info.clientApplicationName; + } else if (mode == Quassel::RunMode::CoreOnly) { + prgname = info.coreApplicationName; + } + + _prgname = prgname.toLocal8Bit(); + // set up options, program name, and facility for later calls to syslog(3) - if (_syslogEnabled) - openlog("quasselcore", LOG_PID, LOG_USER); + if (_syslogEnabled) { + openlog(_prgname.constData(), LOG_PID, LOG_USER); + } #endif _initialized = true; @@ -151,31 +164,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) @@ -234,3 +224,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; +}