Fix usage of logging category on Android

Android logs have a tag/category field in each log entry,
which currently if defined by Qt, it's being included as part
of the message and not used as a tag as it's supposed to be.

This patch fixes that behavior. If a non-default category
is defined, it will be used as a tag, otherwise the application
name is used as before.

Pick-to: 6.2
Fixes: QTBUG-94708
Change-Id: Ie56187f23a47cda6d82e14fdec7c8903d3ee40b6
Reviewed-by: BogDan Vatra <bogdan@kdab.com>
bb10
Assam Boudjelthia 2021-06-25 13:39:47 +03:00
parent 22a058bcf0
commit 87d8ee755b
1 changed files with 7 additions and 1 deletions

View File

@ -1410,7 +1410,10 @@ QString qFormatLogMessage(QtMsgType type, const QMessageLogContext &context, con
} else if (token == messageTokenC) {
message.append(str);
} else if (token == categoryTokenC) {
#ifndef Q_OS_ANDROID
// Don't add the category to the message on Android
message.append(QLatin1String(context.category));
#endif
} else if (token == typeTokenC) {
switch (type) {
case QtDebugMsg: message.append(QLatin1String("debug")); break;
@ -1658,7 +1661,10 @@ static bool android_default_message_handler(QtMsgType type,
break;
};
__android_log_print(priority, qPrintable(QCoreApplication::applicationName()), "%s\n", qPrintable(formattedMessage));
// If a category is defined, use it as an Android logging tag
__android_log_print(priority, isDefaultCategory(context.category) ?
qPrintable(QCoreApplication::applicationName()) : context.category,
"%s\n", qPrintable(formattedMessage));
return true; // Prevent further output to stderr
}