Skip to content

Commit 77fe857

Browse files
committed
ADB log tailing color output
1 parent 35a2e37 commit 77fe857

6 files changed

Lines changed: 55 additions & 2 deletions

File tree

src/briefcase/console.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
SENSITIVE_SETTING_RE = re.compile(r"API|TOKEN|KEY|SECRET|PASS|SIGNATURE", flags=re.I)
3434

3535
# 7-bit C1 ANSI escape sequences
36-
ANSI_ESCAPE_RE = re.compile(r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])")
36+
ANSI_ESC_SEQ_RE_DEF = r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])"
37+
ANSI_ESCAPE_RE = re.compile(ANSI_ESC_SEQ_RE_DEF)
3738

3839

3940
class InputDisabled(Exception):

src/briefcase/integrations/android_sdk.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,6 +1599,8 @@ def logcat(self, pid: str) -> subprocess.Popen:
15991599
self.device,
16001600
"logcat",
16011601
"--format=tag",
1602+
"-v",
1603+
"color",
16021604
"--pid", # This option is available since API level 24.
16031605
pid,
16041606
]
@@ -1627,6 +1629,8 @@ def logcat_tail(self, since: datetime):
16271629
self.device,
16281630
"logcat",
16291631
"--format=tag",
1632+
"-v",
1633+
"color",
16301634
"-t",
16311635
since.strftime("%m-%d %H:%M:%S.000000"),
16321636
"-s",

src/briefcase/platforms/android/gradle.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
UpdateCommand,
1717
)
1818
from briefcase.config import AppConfig, parsed_version
19+
from briefcase.console import ANSI_ESC_SEQ_RE_DEF
1920
from briefcase.exceptions import BriefcaseCommandError
2021
from briefcase.integrations.android_sdk import AndroidSDK
2122
from briefcase.integrations.subprocess import SubprocessArgT
@@ -35,7 +36,11 @@ def safe_formal_name(name):
3536
return re.sub(r"\s+", " ", re.sub(r'[!/\\:<>"\?\*\|]', "", name)).strip()
3637

3738

38-
ANDROID_LOG_PREFIX_REGEX = re.compile(r"[A-Z]/(?P<tag>.*?): (?P<content>.*)")
39+
# Matches zero or more ANSI control chars wrapping the message for when
40+
# the Android emulator is printing in color.
41+
ANDROID_LOG_PREFIX_REGEX = re.compile(
42+
rf"(?:{ANSI_ESC_SEQ_RE_DEF})*[A-Z]/(?P<tag>.*?): (?P<content>.*?(?=\x1B|$))(?:{ANSI_ESC_SEQ_RE_DEF})*"
43+
)
3944

4045

4146
def android_log_clean_filter(line):

tests/integrations/android_sdk/ADB/test_logcat.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ def test_logcat(mock_tools, adb):
2020
"exampleDevice",
2121
"logcat",
2222
"--format=tag",
23+
"-v",
24+
"color",
2325
"--pid",
2426
"1234",
2527
"EGL_emulation:S",

tests/integrations/android_sdk/ADB/test_logcat_tail.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ def test_logcat_tail(mock_tools, adb):
2121
"exampleDevice",
2222
"logcat",
2323
"--format=tag",
24+
"-v",
25+
"color",
2426
"-t",
2527
"11-10 09:08:07.000000",
2628
"-s",

tests/platforms/android/gradle/test_android_log_clean_filter.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
False,
2020
),
2121
),
22+
(
23+
"\x1b[32mD/libEGL : loaded /vendor/lib64/egl/libEGL_emulation.so\x1b[0m",
24+
(
25+
"loaded /vendor/lib64/egl/libEGL_emulation.so",
26+
False,
27+
),
28+
),
2229
(
2330
"D/stdio : Could not find platform independent libraries <prefix>",
2431
("Could not find platform independent libraries <prefix>", False),
@@ -27,28 +34,60 @@
2734
"D/MainActivity: onStart() start",
2835
("onStart() start", False),
2936
),
37+
(
38+
"\x1b[32mD/MainActivity: onStart() start\x1b[0m",
39+
("onStart() start", False),
40+
),
3041
# Python App messages
3142
(
3243
"I/python.stdout: Python app launched & stored in Android Activity class",
3344
("Python app launched & stored in Android Activity class", True),
3445
),
46+
(
47+
"\x1b[32mI/python.stdout: Python app launched & stored in Android Activity class\x1b[0m",
48+
("Python app launched & stored in Android Activity class", True),
49+
),
3550
(
3651
"I/python.stdout: ",
3752
("", True),
3853
),
54+
(
55+
"\x1b[32mI/python.stdout: \x1b[0m",
56+
("", True),
57+
),
58+
(
59+
"\x1b[32m\x1b[98mI/python.stdout: \x1b[32m\x1b[0m",
60+
("", True),
61+
),
62+
(
63+
"\x1b[32m\x1b[98mI/python.stdout: this is colored output\x1b[32m\x1b[0m",
64+
("this is colored output", True),
65+
),
3966
(
4067
"I/python.stderr: test_case (tests.foobar.test_other.TestOtherMethods)",
4168
("test_case (tests.foobar.test_other.TestOtherMethods)", True),
4269
),
70+
(
71+
"\x1b[32mI/python.stderr: test_case (tests.foobar.test_other.TestOtherMethods)\x1b[0m",
72+
("test_case (tests.foobar.test_other.TestOtherMethods)", True),
73+
),
4374
(
4475
"I/python.stderr: ",
4576
("", True),
4677
),
78+
(
79+
"\x1b[32mI/python.stderr: \x1b[0m",
80+
("", True),
81+
),
4782
# Unknown content
4883
(
4984
"This doesn't match the regex",
5085
("This doesn't match the regex", False),
5186
),
87+
(
88+
"\x1b[33mThis doesn't match the regex\x1b[33m",
89+
("\x1b[33mThis doesn't match the regex\x1b[33m", False),
90+
),
5291
],
5392
)
5493
def test_filter(original, filtered):

0 commit comments

Comments
 (0)