Skip to content

Commit 6f7d8b4

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 869799c commit 6f7d8b4

27 files changed

Lines changed: 1521 additions & 171 deletions

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ cf_cc_library(
130130
"//cuttlefish/host/commands/cvd/cli/commands:lint",
131131
"//cuttlefish/host/commands/cvd/cli/commands:login",
132132
"//cuttlefish/host/commands/cvd/cli/commands:logs",
133-
"//cuttlefish/host/commands/cvd/cli/commands:monitor",
134133
"//cuttlefish/host/commands/cvd/cli/commands:power_btn",
135134
"//cuttlefish/host/commands/cvd/cli/commands:powerwash",
136135
"//cuttlefish/host/commands/cvd/cli/commands:remove",
@@ -143,6 +142,7 @@ cf_cc_library(
143142
"//cuttlefish/host/commands/cvd/cli/commands:status",
144143
"//cuttlefish/host/commands/cvd/cli/commands:stop",
145144
"//cuttlefish/host/commands/cvd/cli/commands:version",
145+
"//cuttlefish/host/commands/cvd/cli/commands/monitor:command_handler",
146146
"//cuttlefish/host/commands/cvd/cli/parser:load_config_cc_proto",
147147
"//cuttlefish/host/commands/cvd/cli/parser:load_configs_parser",
148148
"//cuttlefish/host/commands/cvd/cli/selector:creation_analyzer",

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

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("//cuttlefish/bazel:rules.bzl", "cf_cc_library", "cf_cc_test")
1+
load("//cuttlefish/bazel:rules.bzl", "cf_cc_library")
22

33
package(
44
default_visibility = ["//:android_cuttlefish"],
@@ -246,41 +246,6 @@ cf_cc_library(
246246
],
247247
)
248248

249-
cf_cc_library(
250-
name = "monitor",
251-
srcs = ["monitor.cpp"],
252-
hdrs = ["monitor.h"],
253-
deps = [
254-
"//cuttlefish/common/libs/fs",
255-
"//cuttlefish/common/libs/utils:flag_parser",
256-
"//cuttlefish/host/commands/cvd/cli:command_request",
257-
"//cuttlefish/host/commands/cvd/cli:types",
258-
"//cuttlefish/host/commands/cvd/cli:utils",
259-
"//cuttlefish/host/commands/cvd/cli/commands:command_handler",
260-
"//cuttlefish/host/commands/cvd/cli/selector",
261-
"//cuttlefish/host/commands/cvd/instances",
262-
"//cuttlefish/host/commands/cvd/instances:instance_manager",
263-
"//cuttlefish/host/libs/log_names",
264-
"//cuttlefish/result",
265-
"//libbase",
266-
"@abseil-cpp//absl/log:check",
267-
"@abseil-cpp//absl/strings",
268-
"@abseil-cpp//absl/strings:cord",
269-
"@fmt",
270-
],
271-
)
272-
273-
cf_cc_test(
274-
name = "monitor_test",
275-
srcs = ["monitor_test.cpp"],
276-
deps = [
277-
":monitor",
278-
"//cuttlefish/common/libs/fs",
279-
"//cuttlefish/result:result_matchers",
280-
"@abseil-cpp//absl/strings",
281-
],
282-
)
283-
284249
cf_cc_library(
285250
name = "power_btn",
286251
srcs = ["power_btn.cpp"],
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
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/common/libs/utils:environment",
53+
"//cuttlefish/host/libs/log_names",
54+
"//cuttlefish/result",
55+
"@abseil-cpp//absl/log:check",
56+
"@abseil-cpp//absl/strings",
57+
"@abseil-cpp//absl/strings:cord",
58+
],
59+
)
60+
61+
cf_cc_test(
62+
name = "display_test",
63+
srcs = ["display_test.cc"],
64+
clang_format_enabled = True,
65+
deps = [
66+
":display",
67+
"//cuttlefish/common/libs/fs",
68+
"//cuttlefish/result:result_matchers",
69+
"@abseil-cpp//absl/strings",
70+
],
71+
)
72+
73+
cf_cc_library(
74+
name = "kernel",
75+
srcs = ["kernel.cc"],
76+
hdrs = ["kernel.h"],
77+
clang_format_enabled = True,
78+
deps = [
79+
":ansi_codes",
80+
"//cuttlefish/result",
81+
"@abseil-cpp//absl/strings",
82+
],
83+
)
84+
85+
cf_cc_test(
86+
name = "kernel_test",
87+
srcs = ["kernel_test.cc"],
88+
clang_format_enabled = True,
89+
deps = [
90+
":kernel",
91+
"//cuttlefish/result:result_matchers",
92+
],
93+
)
94+
95+
cf_cc_library(
96+
name = "launcher",
97+
srcs = ["launcher.cc"],
98+
hdrs = ["launcher.h"],
99+
clang_format_enabled = True,
100+
deps = [
101+
":ansi_codes",
102+
":truncate",
103+
":verbosity",
104+
"//cuttlefish/result",
105+
"@abseil-cpp//absl/strings",
106+
],
107+
)
108+
109+
cf_cc_test(
110+
name = "launcher_test",
111+
srcs = ["launcher_test.cc"],
112+
clang_format_enabled = True,
113+
deps = [
114+
":launcher",
115+
"//cuttlefish/result:result_matchers",
116+
],
117+
)
118+
119+
cf_cc_library(
120+
name = "log_tee",
121+
srcs = ["log_tee.cc"],
122+
hdrs = ["log_tee.h"],
123+
clang_format_enabled = True,
124+
deps = [
125+
":ansi_codes",
126+
":verbosity",
127+
"//cuttlefish/result",
128+
"@abseil-cpp//absl/strings",
129+
],
130+
)
131+
132+
cf_cc_test(
133+
name = "log_tee_test",
134+
srcs = ["log_tee_test.cc"],
135+
clang_format_enabled = True,
136+
deps = [
137+
":log_tee",
138+
"//cuttlefish/result:result_matchers",
139+
],
140+
)
141+
142+
cf_cc_library(
143+
name = "logcat",
144+
srcs = ["logcat.cc"],
145+
hdrs = ["logcat.h"],
146+
clang_format_enabled = True,
147+
deps = [
148+
":ansi_codes",
149+
":truncate",
150+
":verbosity",
151+
"//cuttlefish/result",
152+
"@abseil-cpp//absl/strings",
153+
],
154+
)
155+
156+
cf_cc_library(
157+
name = "truncate",
158+
srcs = ["truncate.cc"],
159+
hdrs = ["truncate.h"],
160+
clang_format_enabled = True,
161+
deps = [
162+
"@abseil-cpp//absl/strings",
163+
],
164+
)
165+
166+
cf_cc_test(
167+
name = "logcat_test",
168+
srcs = ["logcat_test.cc"],
169+
clang_format_enabled = True,
170+
deps = [
171+
":logcat",
172+
"//cuttlefish/result:result_matchers",
173+
],
174+
)
175+
176+
cf_cc_library(
177+
name = "verbosity",
178+
srcs = ["verbosity.cc"],
179+
hdrs = ["verbosity.h"],
180+
clang_format_enabled = True,
181+
deps = [
182+
":ansi_codes",
183+
],
184+
)
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)