2022-08-26 15:44:59 +00:00
|
|
|
// Copyright 2015 Google LLC. All rights reserved.
|
2015-10-27 18:52:50 +00:00
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
|
|
|
//
|
|
|
|
// Defines verbose logging flags.
|
|
|
|
|
2023-10-10 23:51:11 +00:00
|
|
|
#include <packager/app/vlog_flags.h>
|
2023-10-11 08:49:50 +00:00
|
|
|
|
2023-10-13 19:42:47 +00:00
|
|
|
#include <absl/log/globals.h>
|
|
|
|
#include <absl/log/log.h>
|
2023-10-11 08:49:50 +00:00
|
|
|
#include <absl/strings/numbers.h>
|
|
|
|
|
2023-10-10 23:51:11 +00:00
|
|
|
#include <packager/kv_pairs/kv_pairs.h>
|
2015-10-27 18:52:50 +00:00
|
|
|
|
2023-10-13 19:42:47 +00:00
|
|
|
ABSL_FLAG(int,
|
2023-09-09 00:44:17 +00:00
|
|
|
v,
|
|
|
|
0,
|
|
|
|
"Show all VLOG(m) or DVLOG(m) messages for m <= this. "
|
|
|
|
"Overridable by --vmodule.");
|
2023-10-09 18:08:08 +00:00
|
|
|
|
2023-09-09 00:44:17 +00:00
|
|
|
ABSL_FLAG(
|
|
|
|
std::string,
|
2015-10-27 18:52:50 +00:00
|
|
|
vmodule,
|
|
|
|
"",
|
2023-10-13 19:42:47 +00:00
|
|
|
"Per-module verbose level. THIS FLAG IS DEPRECATED. "
|
2015-10-27 18:52:50 +00:00
|
|
|
"Argument is a comma-separated list of <module name>=<log level>. "
|
2023-10-13 19:42:47 +00:00
|
|
|
"The logging system no longer supports different levels for different "
|
|
|
|
"modules, so the verbosity level will be set to the maximum specified for "
|
|
|
|
"any module or given by --v.");
|
2023-10-09 18:08:08 +00:00
|
|
|
|
2023-10-13 19:42:47 +00:00
|
|
|
ABSL_DECLARE_FLAG(int, minloglevel);
|
2023-10-09 18:08:08 +00:00
|
|
|
|
|
|
|
namespace shaka {
|
|
|
|
|
2023-10-13 19:42:47 +00:00
|
|
|
void handle_vlog_flags() {
|
|
|
|
// Reference the log level flag to keep the absl::log flags from getting
|
|
|
|
// stripped from the executable.
|
|
|
|
int log_level = absl::GetFlag(FLAGS_minloglevel);
|
|
|
|
(void)log_level;
|
2023-10-09 18:08:08 +00:00
|
|
|
|
2023-10-13 19:42:47 +00:00
|
|
|
int vlog_level = absl::GetFlag(FLAGS_v);
|
2023-10-09 18:08:08 +00:00
|
|
|
std::string vmodule_patterns = absl::GetFlag(FLAGS_vmodule);
|
2023-10-13 19:42:47 +00:00
|
|
|
|
2023-10-09 18:08:08 +00:00
|
|
|
if (!vmodule_patterns.empty()) {
|
|
|
|
std::vector<KVPair> patterns =
|
|
|
|
SplitStringIntoKeyValuePairs(vmodule_patterns, '=', ',');
|
|
|
|
int pattern_vlevel;
|
2023-10-13 19:42:47 +00:00
|
|
|
bool warning_shown = false;
|
2023-10-09 18:08:08 +00:00
|
|
|
|
|
|
|
for (const auto& pattern : patterns) {
|
2023-10-13 19:42:47 +00:00
|
|
|
if (!warning_shown) {
|
|
|
|
LOG(WARNING) << "--vmodule ignored, combined with --v!";
|
|
|
|
warning_shown = true;
|
|
|
|
}
|
|
|
|
|
2023-10-09 18:08:08 +00:00
|
|
|
if (!::absl::SimpleAtoi(pattern.second, &pattern_vlevel)) {
|
|
|
|
LOG(ERROR) << "Error parsing log level for '" << pattern.first
|
|
|
|
<< "' from '" << pattern.second << "'";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-10-13 19:42:47 +00:00
|
|
|
|
|
|
|
if (vlog_level != 0) {
|
|
|
|
absl::SetMinLogLevel(static_cast<absl::LogSeverityAtLeast>(-vlog_level));
|
|
|
|
}
|
2023-10-09 18:08:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace shaka
|