summaryrefslogtreecommitdiffstats
path: root/src/corelib/global
diff options
context:
space:
mode:
authorTasuku Suzuki <stasuku@gmail.com>2015-07-04 23:13:31 +0900
committerTasuku Suzuki <stasuku@gmail.com>2015-08-09 04:16:38 +0000
commit26b4ec448cdd68ab260e4a39a493cbdf8eef8d3f (patch)
tree97c5d1ab55db0fa3f1899031065709583b6f94f8 /src/corelib/global
parent89cb92f838b43123f51bfddba433bfe54c0e855d (diff)
Support logging direct to syslog, if enabled.
[ChangeLog][QtCore][Logging] Systems with syslog may now pass -syslog to configure to send logging output to syslog. Change-Id: I80d58ee6e70d8deb2409fc666e7e7f2d7f52b8e1 Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com>
Diffstat (limited to 'src/corelib/global')
-rw-r--r--src/corelib/global/global.pri4
-rw-r--r--src/corelib/global/qlogging.cpp32
2 files changed, 36 insertions, 0 deletions
diff --git a/src/corelib/global/global.pri b/src/corelib/global/global.pri
index 6a8104bee2..43f3a86544 100644
--- a/src/corelib/global/global.pri
+++ b/src/corelib/global/global.pri
@@ -54,3 +54,7 @@ journald {
PKGCONFIG_PRIVATE += libsystemd-journal
DEFINES += QT_USE_JOURNALD
}
+
+syslog {
+ DEFINES += QT_USE_SYSLOG
+}
diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp
index fca8656f9b..20c31f7ef8 100644
--- a/src/corelib/global/qlogging.cpp
+++ b/src/corelib/global/qlogging.cpp
@@ -65,6 +65,9 @@
# include <systemd/sd-journal.h>
# include <syslog.h>
#endif
+#if defined(QT_USE_SYSLOG) && !defined(QT_BOOTSTRAPPED)
+# include <syslog.h>
+#endif
#ifdef Q_OS_UNIX
# include <sys/types.h>
# include <sys/stat.h>
@@ -1436,6 +1439,32 @@ static void systemd_default_message_handler(QtMsgType type,
}
#endif
+#ifdef QT_USE_SYSLOG
+static void syslog_default_message_handler(QtMsgType type, const char *message)
+{
+ int priority = LOG_INFO; // Informational
+ switch (type) {
+ case QtDebugMsg:
+ priority = LOG_DEBUG; // Debug-level messages
+ break;
+ case QtInfoMsg:
+ priority = LOG_INFO; // Informational conditions
+ break;
+ case QtWarningMsg:
+ priority = LOG_WARNING; // Warning conditions
+ break;
+ case QtCriticalMsg:
+ priority = LOG_CRIT; // Critical conditions
+ break;
+ case QtFatalMsg:
+ priority = LOG_ALERT; // Action must be taken immediately
+ break;
+ }
+
+ syslog(priority, "%s", message);
+}
+#endif
+
#ifdef Q_OS_ANDROID
static void android_default_message_handler(QtMsgType type,
const QMessageLogContext &context,
@@ -1481,6 +1510,9 @@ static void qDefaultMessageHandler(QtMsgType type, const QMessageLogContext &con
#elif defined(QT_USE_JOURNALD) && !defined(QT_BOOTSTRAPPED)
systemd_default_message_handler(type, context, logMessage);
return;
+#elif defined(QT_USE_SYSLOG) && !defined(QT_BOOTSTRAPPED)
+ syslog_default_message_handler(type, logMessage.toUtf8().constData());
+ return;
#elif defined(Q_OS_ANDROID)
android_default_message_handler(type, context, logMessage);
return;