David Sánchez
David Sánchez

Reputation: 606

Disable QML console.log() messages

We are tunning the final release of our application, and we successfully disable the debug messages in c++.

CONFIG(release, debug|release):{
    message(Building in release mode. We deactivate the logs.)
    DEFINES += QT_NO_DEBUG_OUTPUT
} else {
    message(Building in debug mode.)
}

But, our QML javascript console.log() functions are still logging the information.

I also found this source that clearly states: The output is generated using the qDebug, qWarning, qCritical methods in C++ (see also Debugging Techniques).

What doesnt make much sense to me, since Im already ignoring all the qDebugs()

So, the question is: How to ignore all the console.log() ?

I just think it should be an easy task, similar to the qDebug() messages.

For any further information, please leave a comment.

Note: I know that the link is for Qt 5., but im using Qt 4.8.

Thanks in advance!

Upvotes: 3

Views: 3763

Answers (2)

Nigel Brown
Nigel Brown

Reputation: 1

Here is what I use for a final release:

qputenv("QT_LOGGING_RULES", QByteArray("*.debug=false;qml=false"));

Upvotes: 0

Mitch
Mitch

Reputation: 24396

If QT_NO_DEBUG_OUTPUT successfully disables output from within Qt code, it should do the same for the C++ functions that implement console.log(). However, I believe that those feature macros are deliberately not auto-tested (too many macros, too few hardware resources to test them on), so any bug report would be closed, and you'd be encouraged to submit a patch yourself.

Another solution might be to use qInstallMessageHandler(), as mentioned in the answers to this question.


Unfortunately this doesn't help you, but in Qt 5, it's enough to disable the logging rule with the QT_LOGGING_RULES environment variable:

QT_LOGGING_RULES=qml=false

Upvotes: 1

Related Questions