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>
This commit is contained in:
parent
2193df65a3
commit
b838170ceb
@ -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);
|
||||
}
|
||||
|
@ -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");
|
||||
|
@ -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}\"");
|
||||
|
Loading…
x
Reference in New Issue
Block a user