Skip to content

Commit 3a54ca5

Browse files
committed
Add colors to cvd monitor
- Introduce component-aware syntax highlighting and coloring for logcat, kernel, launcher, and log_tee streams in `cvd monitor`. - Colorize timestamps, subsystem tags, PIDs/TIDs, and verbosity levels to improve log readability and debugging efficiency. - Restructure log monitoring logic into decoupled structured parsing and formatting pipelines within a new `commands/monitor/` package. - Add comprehensive unit tests for parsing and formatting across all supported log stream formats. Assisted-by: Jetski Bug: b/513710219
1 parent 00d5bd0 commit 3a54ca5

25 files changed

Lines changed: 1328 additions & 170 deletions

base/cvd/cuttlefish/host/commands/cvd/cli/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ cf_cc_library(
100100
"//cuttlefish/host/commands/cvd/cli/commands:lint",
101101
"//cuttlefish/host/commands/cvd/cli/commands:login",
102102
"//cuttlefish/host/commands/cvd/cli/commands:logs",
103-
"//cuttlefish/host/commands/cvd/cli/commands:monitor",
104103
"//cuttlefish/host/commands/cvd/cli/commands:power_btn",
105104
"//cuttlefish/host/commands/cvd/cli/commands:powerwash",
106105
"//cuttlefish/host/commands/cvd/cli/commands:remove",
@@ -113,6 +112,7 @@ cf_cc_library(
113112
"//cuttlefish/host/commands/cvd/cli/commands:status",
114113
"//cuttlefish/host/commands/cvd/cli/commands:stop",
115114
"//cuttlefish/host/commands/cvd/cli/commands:version",
115+
"//cuttlefish/host/commands/cvd/cli/commands/monitor:command_handler",
116116
"//cuttlefish/host/commands/cvd/cli/parser:load_config_cc_proto",
117117
"//cuttlefish/host/commands/cvd/cli/parser:load_configs_parser",
118118
"//cuttlefish/host/commands/cvd/cli/selector:creation_analyzer",

base/cvd/cuttlefish/host/commands/cvd/cli/commands/BUILD.bazel

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -244,41 +244,6 @@ cf_cc_library(
244244
],
245245
)
246246

247-
cf_cc_library(
248-
name = "monitor",
249-
srcs = ["monitor.cpp"],
250-
hdrs = ["monitor.h"],
251-
deps = [
252-
"//cuttlefish/common/libs/fs",
253-
"//cuttlefish/common/libs/utils:flag_parser",
254-
"//cuttlefish/host/commands/cvd/cli:command_request",
255-
"//cuttlefish/host/commands/cvd/cli:types",
256-
"//cuttlefish/host/commands/cvd/cli:utils",
257-
"//cuttlefish/host/commands/cvd/cli/commands:command_handler",
258-
"//cuttlefish/host/commands/cvd/cli/selector",
259-
"//cuttlefish/host/commands/cvd/instances",
260-
"//cuttlefish/host/commands/cvd/instances:instance_manager",
261-
"//cuttlefish/host/libs/log_names",
262-
"//cuttlefish/result",
263-
"//libbase",
264-
"@abseil-cpp//absl/log:check",
265-
"@abseil-cpp//absl/strings",
266-
"@abseil-cpp//absl/strings:cord",
267-
"@fmt",
268-
],
269-
)
270-
271-
cf_cc_test(
272-
name = "monitor_test",
273-
srcs = ["monitor_test.cpp"],
274-
deps = [
275-
":monitor",
276-
"//cuttlefish/common/libs/fs",
277-
"//cuttlefish/result:result_matchers",
278-
"@abseil-cpp//absl/strings",
279-
],
280-
)
281-
282247
cf_cc_library(
283248
name = "power_btn",
284249
srcs = ["power_btn.cpp"],
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
load("//cuttlefish/bazel:rules.bzl", "cf_cc_library", "cf_cc_test")
2+
3+
package(
4+
default_visibility = ["//cuttlefish/host/commands/cvd/cli:__subpackages__"],
5+
)
6+
7+
cf_cc_library(
8+
name = "ansi_codes",
9+
srcs = ["ansi_codes.cc"],
10+
hdrs = ["ansi_codes.h"],
11+
clang_format_enabled = True,
12+
deps = [
13+
"@abseil-cpp//absl/strings",
14+
],
15+
)
16+
17+
cf_cc_library(
18+
name = "command_handler",
19+
srcs = ["command_handler.cc"],
20+
hdrs = ["command_handler.h"],
21+
clang_format_enabled = True,
22+
deps = [
23+
":ansi_codes",
24+
":display",
25+
"//cuttlefish/common/libs/fs",
26+
"//cuttlefish/common/libs/utils:flag_parser",
27+
"//cuttlefish/host/commands/cvd/cli:command_request",
28+
"//cuttlefish/host/commands/cvd/cli:types",
29+
"//cuttlefish/host/commands/cvd/cli:utils",
30+
"//cuttlefish/host/commands/cvd/cli/commands:command_handler",
31+
"//cuttlefish/host/commands/cvd/cli/selector",
32+
"//cuttlefish/host/commands/cvd/instances",
33+
"//cuttlefish/host/commands/cvd/instances:instance_manager",
34+
"//cuttlefish/host/libs/log_names",
35+
"//cuttlefish/result",
36+
"//libbase",
37+
"@abseil-cpp//absl/strings",
38+
],
39+
)
40+
41+
cf_cc_library(
42+
name = "display",
43+
srcs = ["display.cc"],
44+
hdrs = ["display.h"],
45+
clang_format_enabled = True,
46+
deps = [
47+
":kernel",
48+
":launcher",
49+
":log_tee",
50+
":logcat",
51+
"//cuttlefish/common/libs/fs",
52+
"//cuttlefish/host/libs/log_names",
53+
"//cuttlefish/result",
54+
"@abseil-cpp//absl/log:check",
55+
"@abseil-cpp//absl/strings",
56+
"@abseil-cpp//absl/strings:cord",
57+
],
58+
)
59+
60+
cf_cc_test(
61+
name = "display_test",
62+
srcs = ["display_test.cc"],
63+
clang_format_enabled = True,
64+
deps = [
65+
":display",
66+
"//cuttlefish/common/libs/fs",
67+
"//cuttlefish/result:result_matchers",
68+
"@abseil-cpp//absl/strings",
69+
],
70+
)
71+
72+
cf_cc_library(
73+
name = "kernel",
74+
srcs = ["kernel.cc"],
75+
hdrs = ["kernel.h"],
76+
clang_format_enabled = True,
77+
deps = [
78+
":ansi_codes",
79+
"//cuttlefish/result",
80+
"@abseil-cpp//absl/strings",
81+
],
82+
)
83+
84+
cf_cc_test(
85+
name = "kernel_test",
86+
srcs = ["kernel_test.cc"],
87+
clang_format_enabled = True,
88+
deps = [
89+
":kernel",
90+
"//cuttlefish/result:result_matchers",
91+
],
92+
)
93+
94+
cf_cc_library(
95+
name = "launcher",
96+
srcs = ["launcher.cc"],
97+
hdrs = ["launcher.h"],
98+
clang_format_enabled = True,
99+
deps = [
100+
":ansi_codes",
101+
":verbosity",
102+
"//cuttlefish/result",
103+
"@abseil-cpp//absl/strings",
104+
],
105+
)
106+
107+
cf_cc_test(
108+
name = "launcher_test",
109+
srcs = ["launcher_test.cc"],
110+
clang_format_enabled = True,
111+
deps = [
112+
":launcher",
113+
"//cuttlefish/result:result_matchers",
114+
],
115+
)
116+
117+
cf_cc_library(
118+
name = "log_tee",
119+
srcs = ["log_tee.cc"],
120+
hdrs = ["log_tee.h"],
121+
clang_format_enabled = True,
122+
deps = [
123+
":ansi_codes",
124+
":verbosity",
125+
"//cuttlefish/result",
126+
"@abseil-cpp//absl/strings",
127+
],
128+
)
129+
130+
cf_cc_test(
131+
name = "log_tee_test",
132+
srcs = ["log_tee_test.cc"],
133+
clang_format_enabled = True,
134+
deps = [
135+
":log_tee",
136+
"//cuttlefish/result:result_matchers",
137+
],
138+
)
139+
140+
cf_cc_library(
141+
name = "logcat",
142+
srcs = ["logcat.cc"],
143+
hdrs = ["logcat.h"],
144+
clang_format_enabled = True,
145+
deps = [
146+
":ansi_codes",
147+
":verbosity",
148+
"//cuttlefish/result",
149+
"@abseil-cpp//absl/strings",
150+
],
151+
)
152+
153+
cf_cc_test(
154+
name = "logcat_test",
155+
srcs = ["logcat_test.cc"],
156+
clang_format_enabled = True,
157+
deps = [
158+
":logcat",
159+
"//cuttlefish/result:result_matchers",
160+
],
161+
)
162+
163+
cf_cc_library(
164+
name = "verbosity",
165+
srcs = ["verbosity.cc"],
166+
hdrs = ["verbosity.h"],
167+
clang_format_enabled = True,
168+
deps = [
169+
":ansi_codes",
170+
],
171+
)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (C) 2026 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "cuttlefish/host/commands/cvd/cli/commands/monitor/ansi_codes.h"
18+
19+
#include <string>
20+
21+
#include "absl/strings/str_cat.h"
22+
23+
namespace cuttlefish {
24+
25+
std::string AnsiCursorUp(int n) { return absl::StrCat("\033[", n, "A"); }
26+
27+
} // namespace cuttlefish
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (C) 2026 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#pragma once
18+
19+
#include <string>
20+
#include <string_view>
21+
22+
namespace cuttlefish {
23+
24+
inline constexpr std::string_view kAnsiReset = "\033[0m";
25+
inline constexpr std::string_view kAnsiRed = "\033[0;31m";
26+
inline constexpr std::string_view kAnsiGreen = "\033[0;32m";
27+
inline constexpr std::string_view kAnsiYellow = "\033[0;33m";
28+
inline constexpr std::string_view kAnsiCyan = "\033[0;36m";
29+
inline constexpr std::string_view kAnsiWhite = "\033[0;37m";
30+
31+
inline constexpr std::string_view kAnsiClearScreen = "\033[J";
32+
33+
std::string AnsiCursorUp(int n);
34+
35+
} // namespace cuttlefish

0 commit comments

Comments
 (0)