Add the features of QLoggingCategory to QML's debugging methods.
authorGiorgos Tsiapaliokas <terietor@gmail.com>
Wed, 23 Oct 2013 13:47:30 +0000 (16:47 +0300)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Fri, 7 Mar 2014 11:20:24 +0000 (12:20 +0100)
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 <kai.koehne@digia.com>
src/qml/qml/v8/qqmlbuiltinfunctions.cpp
tests/auto/qml/debugger/shared/debugutil.cpp
tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp
tests/auto/qml/qqmlconsole/tst_qqmlconsole.cpp

index fbc4120..8692be6 100644 (file)
@@ -72,6 +72,7 @@
 #include <QtCore/qurl.h>
 #include <QtCore/qfile.h>
 #include <QtCore/qcoreapplication.h>
+#include <QtCore/qloggingcategory.h>
 
 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;
index 560c9ca..0bcbf3e 100644 (file)
@@ -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;
index e744cde..b5b4ed4 100644 (file)
@@ -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
index 43aa82e..42c6578 100644 (file)
@@ -42,6 +42,7 @@
 #include <QDebug>
 #include <QQmlEngine>
 #include <QQmlComponent>
+#include <QLoggingCategory>
 #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");