Skip to content

Commit 3f2255a

Browse files
committed
Fix cvd fetch logging
It was logging at INFO level only to fetch.log. Removes handling of the verbosity flag at the fetch command handler level and leaves it at cvd level only.
1 parent a4e2a96 commit 3f2255a

File tree

6 files changed

+18
-33
lines changed

6 files changed

+18
-33
lines changed

base/cvd/cuttlefish/host/commands/cvd/cli/commands/fetch.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
#include "cuttlefish/host/commands/cvd/cli/commands/fetch.h"
1818

19-
#include <unistd.h>
20-
2119
#include <memory>
2220
#include <string>
2321
#include <utility>
@@ -59,10 +57,7 @@ Result<void> CvdFetchCommandHandler::Handle(const CommandRequest& request) {
5957
CF_EXPECT(EnsureDirectoryExists(flags.target_directory));
6058

6159
std::string log_file = GetFetchLogsFileName(flags.target_directory);
62-
MetadataLevel metadata_level =
63-
isatty(0) ? MetadataLevel::ONLY_MESSAGE : MetadataLevel::FULL;
64-
ScopedLogger logger(
65-
SeverityTarget::FromFile(log_file, metadata_level, flags.verbosity), "");
60+
ScopedLogger logger(SeverityTarget::FromFile(log_file), "");
6661

6762
Result<std::vector<FetchResult>> result = FetchCvdMain(flags);
6863
if (flags.build_api_flags.enable_caching) {

base/cvd/cuttlefish/host/commands/cvd/cli/commands/load_configs.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,7 @@ class LoadConfigsCommand : public CvdCommandHandler {
198198
return CF_EXPECT(
199199
CommandRequestBuilder()
200200
.SetEnv(request.Env())
201-
// The fetch operation is too verbose by default, set it to WARNING
202-
// unconditionally, the full logs are available in fetch.log
203-
// anyways.
204-
.AddArguments({"cvd", "fetch", "-verbosity", "WARNING"})
201+
.AddArguments({"cvd", "fetch"})
205202
.AddArguments(cvd_flags.fetch_cvd_flags)
206203
.Build());
207204
}

base/cvd/cuttlefish/host/commands/cvd/cli/selector/selector_constants.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class SelectorFlags {
4242
public:
4343
static constexpr char kGroupName[] = "group_name";
4444
static constexpr char kInstanceName[] = "instance_name";
45-
static constexpr char kVerbosity[] = "verbosity";
4645
};
4746

4847
} // namespace selector

base/cvd/cuttlefish/host/commands/cvd/fetch/fetch_cvd_parser.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ std::vector<Flag> GetFlagsVector(FetchFlags& fetch_flags,
5656
flags.emplace_back(GflagsCompatFlag("keep_downloaded_archives",
5757
fetch_flags.keep_downloaded_archives)
5858
.Help("Keep downloaded zip/tar."));
59-
flags.emplace_back(VerbosityFlag(fetch_flags.verbosity));
6059
flags.emplace_back(
6160
GflagsCompatFlag("host_package_build", fetch_flags.host_package_build)
6261
.Help("source for the host cvd tools"));

base/cvd/cuttlefish/host/commands/cvd/fetch/fetch_cvd_parser.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <string>
2020
#include <vector>
2121

22-
#include "cuttlefish/common/libs/utils/tee_logging.h"
2322
#include "cuttlefish/host/commands/cvd/fetch/build_api_flags.h"
2423
#include "cuttlefish/host/commands/cvd/fetch/vector_flags.h"
2524
#include "cuttlefish/result/result.h"
@@ -37,7 +36,6 @@ struct FetchFlags {
3736
std::string target_directory = kDefaultTargetDirectory;
3837
std::optional<BuildString> host_package_build;
3938
bool keep_downloaded_archives = kDefaultKeepDownloadedArchives;
40-
LogSeverity verbosity = LogSeverity::Info;
4139
bool helpxml = false;
4240
BuildApiFlags build_api_flags;
4341
VectorFlags vector_flags;

base/cvd/cuttlefish/host/commands/cvd/main.cc

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,13 @@ namespace cuttlefish {
4848
namespace {
4949

5050
/**
51-
* Returns --verbosity value if ever exist in the entire commandline args
51+
* Extracts --verbosity value if ever exist in the entire commandline args
5252
*
5353
* Note that this will also pick up from the subtool arguments:
5454
* e.g. cvd start --verbosity=DEBUG
5555
*
56-
* This may be incorrect as the verbosity should be ideally applied to the
57-
* launch_cvd/cvd_internal_start only.
58-
*
59-
* However, parsing the --verbosity flag only from the driver is quite
60-
* complicated as we do not know the full list of the subcommands,
61-
* the subcommands flags, and even the selector/driver flags.
62-
*
63-
* Thus, we live with the corner case for now.
6456
*/
65-
LogSeverity CvdVerbosityOption(const int argc, char** argv) {
66-
cvd_common::Args all_args = ArgsToVec(argc, argv);
57+
LogSeverity CvdVerbosityOption(cvd_common::Args& all_args) {
6758
std::string verbosity_flag_value;
6859
std::vector<Flag> verbosity_flag{
6960
GflagsCompatFlag("verbosity", verbosity_flag_value)};
@@ -74,8 +65,12 @@ LogSeverity CvdVerbosityOption(const int argc, char** argv) {
7465
if (verbosity_flag_value.empty()) {
7566
return LogSeverity::Info;
7667
}
77-
Result<LogSeverity> encoded_verbosity = ToSeverity(verbosity_flag_value);
78-
return (encoded_verbosity.ok() ? *encoded_verbosity : LogSeverity::Info);
68+
Result<LogSeverity> to_severity_res = ToSeverity(verbosity_flag_value);
69+
if (!to_severity_res.ok()) {
70+
return LogSeverity::Info;
71+
}
72+
LogSeverity verbosity = *to_severity_res;
73+
return verbosity;
7974
}
8075

8176
Result<void> EnsureCvdDirectoriesExist() {
@@ -115,13 +110,12 @@ void IncreaseFileLimit() {
115110
}
116111
}
117112

118-
Result<void> CvdMain(int argc, char** argv, char** envp) {
113+
Result<void> CvdMain(cvd_common::Args all_args, char** envp) {
119114
if (!isatty(0)) {
120115
LOG(INFO) << GetVersionIds().ToString();
121116
}
122117
CF_EXPECT(EnsureCvdDirectoriesExist());
123118

124-
cvd_common::Args all_args = ArgsToVec(argc, argv);
125119
CF_EXPECT(!all_args.empty());
126120

127121
auto env = EnvpToMap(envp);
@@ -214,16 +208,19 @@ bool ValidateHostConfiguration() {
214208
int main(int argc, char** argv, char** envp) {
215209
srand(time(NULL));
216210

211+
cuttlefish::cvd_common::Args all_args = cuttlefish::ArgsToVec(argc, argv);
217212
cuttlefish::LogSeverity verbosity =
218-
cuttlefish::CvdVerbosityOption(argc, argv);
213+
cuttlefish::CvdVerbosityOption(all_args);
219214
// set verbosity for this process
220-
cuttlefish::LogToStderr("", cuttlefish::MetadataLevel::ONLY_MESSAGE,
221-
verbosity);
215+
cuttlefish::MetadataLevel metadata_level =
216+
isatty(0) ? cuttlefish::MetadataLevel::ONLY_MESSAGE
217+
: cuttlefish::MetadataLevel::FULL;
218+
cuttlefish::LogToStderr("", metadata_level, verbosity);
222219

223220
if (!cuttlefish::ValidateHostConfiguration()) {
224221
return -1;
225222
}
226-
auto result = cuttlefish::CvdMain(argc, argv, envp);
223+
auto result = cuttlefish::CvdMain(std::move(all_args), envp);
227224
if (result.ok()) {
228225
return 0;
229226
} else {

0 commit comments

Comments
 (0)