From 26b4ec448cdd68ab260e4a39a493cbdf8eef8d3f Mon Sep 17 00:00:00 2001 From: Tasuku Suzuki Date: Sat, 4 Jul 2015 23:13:31 +0900 Subject: 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 --- src/corelib/global/global.pri | 4 ++++ src/corelib/global/qlogging.cpp | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) (limited to 'src') 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 # include #endif +#if defined(QT_USE_SYSLOG) && !defined(QT_BOOTSTRAPPED) +# include +#endif #ifdef Q_OS_UNIX # include # include @@ -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; -- cgit v1.2.3