qtdebug_syslog
authorDebian Qt/KDE Maintainers <debian-qt-kde@lists.debian.org>
Tue, 5 Feb 2013 21:52:29 +0000 (21:52 +0000)
committerLisandro Damián Nicanor Pérez Meyer <lisandro@debian.org>
Tue, 5 Feb 2013 21:52:29 +0000 (21:52 +0000)
Gbp-Pq: Name qtdebug_syslog.patch

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

index dde8ada9bffb18028fedb4e7f09cab48e2d364e2..3a28a21911d3da0e00bb4c8265b5f5568071b29b 100644 (file)
@@ -50,6 +50,7 @@
 
 #ifndef QT_NO_QOBJECT
 #include <private/qthread_p.h>
+#include <private/qcoreapplication_p.h>
 #endif
 
 #include <stdio.h>
@@ -87,6 +88,8 @@
 
 _LIT(qt_S60Filter, "Series60v?.*.sis");
 _LIT(qt_symbianSystemInstallDir, "z:\\system\\install\\");
+#elif defined(Q_OS_UNIX)
+#include <syslog.h>
 #endif
 
 QT_BEGIN_NAMESPACE
@@ -2225,6 +2228,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 f167d2b01bad393228e7c75c1de0a16c643da806..eb2d41d513b45e0684e656e21837f1d1d9c3ccba 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;
     virtual void createEventDispatcher();
     static void removePostedEvent(QEvent *);