+
+void Logger::handleMessage(LogLevel level, const QString &msg)
+{
+ QString logString;
+
+ 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});
+}
+
+
+void Logger::onMessageLogged(const LogEntry &message)
+{
+ if (_keepMessages) {
+ _messages.push_back(message);
+ }
+
+ // If setup() wasn't called yet, just store the message - will be output later
+ if (_initialized) {
+ outputMessage(message);
+ }
+}
+
+
+void Logger::outputMessage(const LogEntry &message)
+{
+ if (message.logLevel < _outputLevel) {
+ return;
+ }
+
+#ifdef HAVE_SYSLOG
+ if (_syslogEnabled) {
+ int prio{LOG_INFO};
+ switch (message.logLevel) {
+ case LogLevel::Debug:
+ prio = LOG_DEBUG;
+ break;
+ case LogLevel::Info:
+ prio = LOG_INFO;
+ break;
+ case LogLevel::Warning:
+ prio = LOG_WARNING;
+ break;
+ case LogLevel::Error:
+ prio = LOG_ERR;
+ break;
+ case LogLevel::Fatal:
+ prio = LOG_CRIT;
+ }
+ syslog(prio|LOG_USER, "%s", qPrintable(message.message));
+ }
+#endif
+
+ if (!_logFile.fileName().isEmpty() || !_syslogEnabled) {
+ _logFile.write(msgWithTime(message));
+ }
+
+#ifndef Q_OS_MAC
+ // For fatal messages, write log to dump file
+ if (message.logLevel == LogLevel::Fatal) {
+ QFile dumpFile{Quassel::instance()->coreDumpFileName()};
+ if (dumpFile.open(QIODevice::Append)) {
+ dumpFile.write(msgWithTime(message));
+ dumpFile.close();
+ }
+ }
+#endif
+