From c522831cb33d803cbac7858e3ec83b54c0a2fd6c Mon Sep 17 00:00:00 2001 From: Assam Boudjelthia Date: Sat, 12 Oct 2024 16:19:16 +0300 Subject: [PATCH] Android: use colors for logcat adb supports color formatting, so we can use that to get colored log lines. At the same time use brief format to reduce the amount of the text we receive. Also, to make the logs shorter get rid of the repeating pid section. Change-Id: I67a8f64504470322ab3e25a74fbc7111ece9222b Reviewed-by: hjk Reviewed-by: Jarek Kobus --- src/plugins/android/androidrunnerworker.cpp | 40 ++++++++++----------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/src/plugins/android/androidrunnerworker.cpp b/src/plugins/android/androidrunnerworker.cpp index 4033a86d2ce..c19ca7abba7 100644 --- a/src/plugins/android/androidrunnerworker.cpp +++ b/src/plugins/android/androidrunnerworker.cpp @@ -426,40 +426,37 @@ static ExecutableItem logcatRecipe(const Storage &storage) } static const QRegularExpression regExpLogcat{ - "^[0-9\\-]*" // date - "\\s+" - "[0-9\\-:.]*"// time + "^\\x1B\\[[0-9]+m" // color + "(\\w/)" // message type 1. capture + ".*" // source + "(\\(\\s*\\d*\\)):" // pid 2. capture "\\s*" - "(\\d*)" // pid 1. capture - "\\s+" - "\\d*" // unknown - "\\s+" - "(\\w)" // message type 2. capture - "\\s+" - "(.*): " // source 3. capture - "(.*)" // message 4. capture + ".*" // message + "\\x1B\\[[0-9]+m" // color "[\\n\\r]*$" }; + static QStringList errorMsgTypes{"F/", "E/", "W/"}; const bool onlyError = channel == QProcess::StandardError; const QRegularExpressionMatch match = regExpLogcat.match(line); if (match.hasMatch()) { - // Android M - if (match.captured(1) == pidString) { - const QString msgType = match.captured(2); - const QString output = line.mid(match.capturedStart(2)); - if (onlyError || msgType == "F" || msgType == "E" || msgType == "W") + const QString pidMatch = match.captured(2); + const QString cleanPidMatch = pidMatch.mid(1, pidMatch.size() - 2).trimmed(); + if (cleanPidMatch == pidString) { + const QString msgType = match.captured(1); + const QString output = QString(line).remove(pidMatch); + if (onlyError || errorMsgTypes.contains(msgType)) storagePtr->m_glue->addStdErr(output); else storagePtr->m_glue->addStdOut(output); } } else { - if (onlyError || line.startsWith("F/") || line.startsWith("E/") - || line.startsWith("W/")) { + // Get type excluding the initial color characters + const QString msgType = line.mid(5, 7); + if (onlyError || errorMsgTypes.contains(msgType)) storagePtr->m_glue->addStdErr(line); - } else { + else storagePtr->m_glue->addStdOut(line); - } } } }; @@ -469,7 +466,8 @@ static ExecutableItem logcatRecipe(const Storage &storage) QObject::connect(&process, &Process::readyReadStandardError, &process, [parseLogcat] { parseLogcat(QProcess::StandardError); }); - process.setCommand(storage->adbCommand({"logcat", bufferStorage->timeArgs})); + process.setCommand(storage->adbCommand({"logcat", "-v", "color", "-v", "brief", + bufferStorage->timeArgs})); }; return Group {