From: Giorgos Tsiapaliokas Date: Wed, 23 Oct 2013 13:47:30 +0000 (+0300) Subject: Add the features of QLoggingCategory to QML's debugging methods. X-Git-Tag: upstream/5.2.90+alpha~30 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6e5caf0431f63a8b67b4d787ba02d8684dbaa856;p=platform%2Fupstream%2Fqtdeclarative.git Add the features of QLoggingCategory to QML's debugging methods. It is now possible to modify the output of QML's debugging methods. Also the prefix of "qml" makes it possible to capture the output from the QML files using qInstallMessageHandler. This commit depends on qtbase/4967c7106568d5df0be4d40bf793583c7c6bdb69 Change-Id: I2c7a2cb96a0b91fd3249dc2dacbab63e6ac68243 Reviewed-by: Kai Koehne --- diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp index fbc4120..8692be6 100644 --- a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp +++ b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp @@ -72,6 +72,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -1385,19 +1386,24 @@ static QV4::ReturnedValue writeToConsole(ConsoleLogTypes logType, CallContext *c result.append(jsStack(v4)); } + static QLoggingCategory loggingCategory("qml"); QV4::StackFrame frame = v4->currentStackFrame(); const QByteArray baSource = frame.source.toUtf8(); const QByteArray baFunction = frame.function.toUtf8(); - QMessageLogger logger(baSource.constData(), frame.line, baFunction.constData()); + QMessageLogger logger(baSource.constData(), frame.line, baFunction.constData(), loggingCategory.categoryName()); + switch (logType) { case Log: - logger.debug("%s", qPrintable(result)); + if (loggingCategory.isDebugEnabled()) + logger.debug("%s", result.toUtf8().constData()); break; case Warn: - logger.warning("%s", qPrintable(result)); + if (loggingCategory.isWarningEnabled()) + logger.warning("%s", result.toUtf8().constData()); break; case Error: - logger.critical("%s", qPrintable(result)); + if (loggingCategory.isCriticalEnabled()) + logger.critical("%s", result.toUtf8().constData()); break; default: break; diff --git a/tests/auto/qml/debugger/shared/debugutil.cpp b/tests/auto/qml/debugger/shared/debugutil.cpp index 560c9ca..0bcbf3e 100644 --- a/tests/auto/qml/debugger/shared/debugutil.cpp +++ b/tests/auto/qml/debugger/shared/debugutil.cpp @@ -235,9 +235,6 @@ void QQmlDebugProcess::processAppOutput() m_eventLoop.quit(); continue; } - } else if (line.startsWith("qml:")) { - // ### Can't enable quiet mode because that also suppresses application output - continue; //We don't use these, but they aren't output from the app either } else { // set to true if there is output not coming from the debugger outputFromAppItself = true; diff --git a/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp b/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp index e744cde..b5b4ed4 100644 --- a/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp +++ b/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp @@ -117,7 +117,7 @@ void tst_qqmlapplicationengine::application() QCOMPARE(testProcess->exitCode(), 0); QByteArray test_stdout = testProcess->readAllStandardOutput(); QByteArray test_stderr = testProcess->readAllStandardError(); - QByteArray test_stderr_target("Start: testData\nEnd\n"); + QByteArray test_stderr_target("qml: Start: testData\nqml: End\n"); #ifdef Q_OS_WIN test_stderr_target.replace('\n', QByteArray("\r\n")); #endif diff --git a/tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp b/tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp index 43aa82e..42c6578 100644 --- a/tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp +++ b/tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include "../../shared/util.h" class tst_qqmlconsole : public QQmlDataTest @@ -65,6 +66,11 @@ void tst_qqmlconsole::logging() { QUrl testUrl = testFileUrl("logging.qml"); + QLoggingCategory loggingCategory("qml"); + QVERIFY(loggingCategory.isDebugEnabled()); + QVERIFY(loggingCategory.isWarningEnabled()); + QVERIFY(loggingCategory.isCriticalEnabled()); + QTest::ignoreMessage(QtDebugMsg, "console.debug"); QTest::ignoreMessage(QtDebugMsg, "console.log"); QTest::ignoreMessage(QtDebugMsg, "console.info");