I'm using qSetMessagePattern()
to customize the log formatting of a Qt application. On Windows, qDebug()
outputs exactly what I expect, but on Android it adds some information before.
For example
qSetMessagePattern("[D] %{message}");
qDebug("Debug test");
Windows output:
[D] Debug test
Android output:
D/Qt (30070): ..\project\filename.cpp:521 (void Class::method()): [D] Debug test
I've tried making a custom handler (and installing it with qInstallMessageHandler()
), but I don't know how the message handler should output debug information on Android
The question: How to make Android message handler to stop prepending that information, or how to write a custom message handler for Android.
Found the code of the default message handler for android, and formatting is hardcoded, so I write a similar version:
#include <android/log.h>
static void android_message_handler(QtMsgType type,
const QMessageLogContext &context,
const QString &message)
{
android_LogPriority priority = ANDROID_LOG_DEBUG;
switch (type) {
case QtDebugMsg: priority = ANDROID_LOG_DEBUG; break;
case QtWarningMsg: priority = ANDROID_LOG_WARN; break;
case QtCriticalMsg: priority = ANDROID_LOG_ERROR; break;
case QtFatalMsg: priority = ANDROID_LOG_FATAL; break;
};
__android_log_print(priority, "Qt", "%s", qPrintable(message));
}
And installed it with:
qInstallMessageHandler(android_message_handler);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With