qtdebug_syslog
authorDebian Qt/KDE Maintainers <debian-qt-kde@lists.debian.org>
Sun, 14 Jun 2015 16:38:43 +0000 (16:38 +0000)
committerRaspbian forward porter <root@raspbian.org>
Sun, 14 Jun 2015 16:38:43 +0000 (16:38 +0000)
Gbp-Pq: Name qtdebug_syslog.patch

src/corelib/global/qglobal.cpp
src/corelib/kernel/qcoreapplication_p.h

index aaad58ea44e5e519387d06b436388dc9f9df2b6c..7412da2887b91f2ab26f50a9c56d760c35f7dde2 100644 (file)
@@ -50,6 +50,7 @@
 
 #ifndef QT_NO_QOBJECT
 #include <private/qthread_p.h>
+#include <private/qcoreapplication_p.h>
 #endif
 
 #include <stdio.h>
@@ -92,6 +93,8 @@
 
 _LIT(qt_S60Filter, "Series60v?.*.sis");
 _LIT(qt_symbianSystemInstallDir, "z:\\system\\install\\");
+#elif defined(Q_OS_UNIX)
+#include <syslog.h>
 #endif
 
 QT_BEGIN_NAMESPACE
@@ -2327,6 +2330,27 @@ void qt_message_output(QtMsgType msgType, const char *buf)
 #else
         fprintf(stderr, "%s\n", buf);
         fflush(stderr);
+
+        if (qgetenv("QT_USE_SYSLOG").toInt() > 0) {
+            static bool logOpened = false;
+            if (!logOpened) {
+                QByteArray appname;
+#ifndef QT_NO_QOBJECT
+                appname = QCoreApplication::applicationName().toLatin1(); // don't use the local codec here
+                if (appname.isEmpty())
+                    appname = QCoreApplicationPrivate::staticAppName().toLatin1();
+#endif
+                if (appname.isEmpty())
+                    appname = "unknown-qt-application";
+                openlog(appname, LOG_NOWAIT | LOG_PID, LOG_USER);
+                logOpened = true;
+            }
+
+            int level = msgType == QtFatalMsg ? LOG_ERR :
+                        msgType == QtWarningMsg ? LOG_WARNING :
+                        LOG_DEBUG;
+            syslog(level, "%s", buf);
+        }
 #endif
     }
 
index d370356dc6a337fe07dabc3dd4284c4298a8d45d..470a8a4cac00a19875a66583f7e94e885571c8fc 100644 (file)
@@ -86,6 +86,8 @@ public:
     bool sendThroughObjectEventFilters(QObject *, QEvent *);
     bool notify_helper(QObject *, QEvent *);
 
+    static QString staticAppName()
+    { return QCoreApplication::self ? QCoreApplication::self->d_func()->appName() : QString(); }
     virtual QString appName() const;
     mutable QString applicationName;