summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qlogging.cpp
diff options
context:
space:
mode:
authorAssam Boudjelthia <assam.boudjelthia@qt.io>2021-06-25 13:39:47 +0300
committerAssam Boudjelthia <assam.boudjelthia@qt.io>2021-06-28 16:10:16 +0300
commit87d8ee755bfdef8e72a122789c2e3ed382881a12 (patch)
tree163c4bce2acf761e84cca12c5a849e9f80f3b437 /src/corelib/global/qlogging.cpp
parent22a058bcf03a706297ea9484bda0d8331c4c05d5 (diff)
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>
Diffstat (limited to 'src/corelib/global/qlogging.cpp')
-rw-r--r--src/corelib/global/qlogging.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp
index f4fac3f35e..9bb15d21be 100644
--- a/src/corelib/global/qlogging.cpp
+++ b/src/corelib/global/qlogging.cpp
@@ -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
}