summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Faure <faure@kde.org>2012-02-12 01:39:47 +0100
committerQt by Nokia <qt-info@nokia.com>2012-02-17 05:25:56 +0100
commitb838170cebc8d1adefc6c8de34e6a39494ffd75e (patch)
tree876b5edca2939ac9c402c0bb81a96b8220b981b5
parent2193df65a380e27b839bae3dc63ad7496af575e8 (diff)
QDebug: Add support for %{pid}, %{appname} and %{threadid}
Change-Id: I4add0a374e6524b615c6dc0ecfb010a90075b04f Reviewed-by: Kai Koehne <kai.koehne@nokia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r--src/corelib/global/qlogging.cpp23
-rw-r--r--tests/auto/corelib/global/qlogging/app/main.cpp7
-rw-r--r--tests/auto/corelib/global/qlogging/tst_qlogging.cpp10
3 files changed, 32 insertions, 8 deletions
diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp
index 8a75f5a9ea..77c147bc54 100644
--- a/src/corelib/global/qlogging.cpp
+++ b/src/corelib/global/qlogging.cpp
@@ -45,6 +45,10 @@
#include "qstring.h"
#include "qvarlengtharray.h"
#include "qdebug.h"
+#ifndef QT_BOOTSTRAPPED
+#include "qcoreapplication.h"
+#include "qthread.h"
+#endif
#include <stdio.h>
@@ -489,6 +493,9 @@ static const char messageTokenC[] = "%{message}";
static const char fileTokenC[] = "%{file}";
static const char lineTokenC[] = "%{line}";
static const char functionTokenC[] = "%{function}";
+static const char pidTokenC[] = "%{pid}";
+static const char appnameTokenC[] = "%{appname}";
+static const char threadidTokenC[] = "%{threadid}";
static const char emptyTokenC[] = "";
struct QMessagePattern {
@@ -558,6 +565,12 @@ QMessagePattern::QMessagePattern()
tokens[i] = lineTokenC;
else if (lexeme == QLatin1String(functionTokenC))
tokens[i] = functionTokenC;
+ else if (lexeme == QLatin1String(pidTokenC))
+ tokens[i] = pidTokenC;
+ else if (lexeme == QLatin1String(appnameTokenC))
+ tokens[i] = appnameTokenC;
+ else if (lexeme == QLatin1String(threadidTokenC))
+ tokens[i] = threadidTokenC;
else {
fprintf(stderr, "%s\n",
QString::fromLatin1("QT_MESSAGE_PATTERN: Unknown placeholder %1\n"
@@ -624,12 +637,20 @@ Q_CORE_EXPORT QByteArray qMessageFormatString(QtMsgType type, const QMessageLogC
else
message.append("unknown");
} else if (token == lineTokenC) {
- message.append(QString::number(context.line).toLatin1().constData());
+ message.append(QByteArray::number(context.line));
} else if (token == functionTokenC) {
if (context.function)
message.append(qCleanupFuncinfo(context.function));
else
message.append("unknown");
+#ifndef QT_BOOTSTRAPPED
+ } else if (token == pidTokenC) {
+ message.append(QByteArray::number(QCoreApplication::applicationPid()));
+ } else if (token == appnameTokenC) {
+ message.append(QCoreApplication::applicationName().toUtf8().constData());
+ } else if (token == threadidTokenC) {
+ message.append("0x" + QByteArray::number(qlonglong(QThread::currentThread()->currentThread()), 16));
+#endif
} else {
message.append(token);
}
diff --git a/tests/auto/corelib/global/qlogging/app/main.cpp b/tests/auto/corelib/global/qlogging/app/main.cpp
index c26b29ea56..dfa52315c7 100644
--- a/tests/auto/corelib/global/qlogging/app/main.cpp
+++ b/tests/auto/corelib/global/qlogging/app/main.cpp
@@ -39,15 +39,18 @@
**
****************************************************************************/
-#include <qglobal.h>
+#include <QCoreApplication>
struct T {
T() { qDebug("static constructor"); }
~T() { qDebug("static destructor"); }
} t;
-int main(int, char **)
+int main(int argc, char **argv)
{
+ QCoreApplication app(argc, argv);
+ app.setApplicationName("tst_qlogging");
+
qDebug("qDebug");
qWarning("qWarning");
qCritical("qCritical");
diff --git a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp
index b2935ea6f2..11949cf1db 100644
--- a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp
+++ b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp
@@ -620,7 +620,7 @@ void tst_qmessagehandler::qMessagePattern()
QStringList environment = QProcess::systemEnvironment();
// %{file} is tricky because of shadow builds
- environment.prepend("QT_MESSAGE_PATTERN=\"%{type} %{line} %{function} %{message}\"");
+ environment.prepend("QT_MESSAGE_PATTERN=\"%{type} %{appname} %{line} %{function} %{message}\"");
process.setEnvironment(environment);
#ifdef Q_OS_WIN
process.start("app/app.exe");
@@ -633,12 +633,12 @@ void tst_qmessagehandler::qMessagePattern()
// qDebug() << output;
QVERIFY(!output.isEmpty());
- QVERIFY(output.contains("debug 45 T::T static constructor"));
+ QVERIFY(output.contains("debug 45 T::T static constructor"));
// we can't be sure whether the QT_MESSAGE_PATTERN is already destructed
QVERIFY(output.contains("static destructor"));
- QVERIFY(output.contains("debug 51 main qDebug"));
- QVERIFY(output.contains("warning 52 main qWarning"));
- QVERIFY(output.contains("critical 53 main qCritical"));
+ QVERIFY(output.contains("debug tst_qlogging 54 main qDebug"));
+ QVERIFY(output.contains("warning tst_qlogging 55 main qWarning"));
+ QVERIFY(output.contains("critical tst_qlogging 56 main qCritical"));
environment = QProcess::systemEnvironment();
environment.prepend("QT_MESSAGE_PATTERN=\"PREFIX: %{unknown} %{message}\"");