diff options
author | Assam Boudjelthia <assam.boudjelthia@qt.io> | 2021-06-25 13:39:47 +0300 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-06-28 15:04:44 +0000 |
commit | eb4b6e8f3574296e1f864fc7a5dfdef147bc5839 (patch) | |
tree | 0ffd31c170c0575a75401dd4c1b14df408d3821b /src | |
parent | 494dac682bb34521d9b5191ede30534882f64286 (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.
Fixes: QTBUG-94708
Change-Id: Ie56187f23a47cda6d82e14fdec7c8903d3ee40b6
Reviewed-by: BogDan Vatra <bogdan@kdab.com>
(cherry picked from commit 87d8ee755bfdef8e72a122789c2e3ed382881a12)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/global/qlogging.cpp | 8 |
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 } |