feat: add verbose logging flags for CMake branch (#1266)

Co-authored-by: Joey Parrish <joeyparrish@google.com>
This commit is contained in:
Cosmin Stejerean 2023-10-09 11:08:08 -07:00 committed by GitHub
parent 8b87804c57
commit 72117f85ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 2 deletions

View File

@ -16,6 +16,7 @@
#include "packager/mpd/util/mpd_writer.h"
#include "packager/tools/license_notice.h"
#include "packager/version/version.h"
#include "vlog_flags.h"
#if defined(OS_WIN)
#include <codecvt>
@ -120,6 +121,8 @@ int MpdMain(int argc, char** argv) {
return status;
}
register_flags_with_glog();
if (!absl::GetFlag(FLAGS_test_packager_version).empty())
SetPackagerVersionForTesting(absl::GetFlag(FLAGS_test_packager_version));

View File

@ -31,6 +31,7 @@
#include "packager/tools/license_notice.h"
#include "packager/utils/string_trim_split.h"
#include "retired_flags.h"
#include "vlog_flags.h"
#if defined(OS_WIN)
#include <codecvt>
@ -555,6 +556,8 @@ int PackagerMain(int argc, char** argv) {
if (absl::GetFlag(FLAGS_quiet))
google::SetStderrLogging(google::GLOG_WARNING);
register_flags_with_glog();
if (!ValidateWidevineCryptoFlags() || !ValidateRawKeyCryptoFlags() ||
!ValidatePRCryptoFlags() || !ValidateCryptoFlags() ||
!ValidateRetiredFlags()) {

View File

@ -7,12 +7,15 @@
// Defines verbose logging flags.
#include "packager/app/vlog_flags.h"
#include "absl/strings/numbers.h"
#include "packager/kv_pairs/kv_pairs.h"
ABSL_FLAG(int32_t,
v,
0,
"Show all VLOG(m) or DVLOG(m) messages for m <= this. "
"Overridable by --vmodule.");
ABSL_FLAG(
std::string,
vmodule,
@ -26,3 +29,41 @@ ABSL_FLAG(
"? and * in the glob pattern match any single or sequence of characters "
"respectively including slashes. "
"<log level> overrides any value given by --v.");
// logging.h defines FLAGS_v and FLAGS_vmodule in terms of the gflags library,
// which we do not use. Here we use macros to rename those symbols to avoid a
// conflict with the flags we defined above using absl. When we switch from
// glog to absl::logging, this workaround should be removed.
#define FLAGS_v GLOG_FLAGS_v
#define FLAGS_vmodule GLOG_FLAGS_vmodule
#include <glog/logging.h>
#undef FLAGS_vmodule
#undef FLAGS_v
namespace shaka {
void register_flags_with_glog() {
auto vlog_level = absl::GetFlag(FLAGS_v);
if (vlog_level != 0) {
google::SetVLOGLevel("*", vlog_level);
}
std::string vmodule_patterns = absl::GetFlag(FLAGS_vmodule);
if (!vmodule_patterns.empty()) {
std::vector<KVPair> patterns =
SplitStringIntoKeyValuePairs(vmodule_patterns, '=', ',');
int pattern_vlevel;
for (const auto& pattern : patterns) {
if (!::absl::SimpleAtoi(pattern.second, &pattern_vlevel)) {
LOG(ERROR) << "Error parsing log level for '" << pattern.first
<< "' from '" << pattern.second << "'";
continue;
}
google::SetVLOGLevel(pattern.first.c_str(), pattern_vlevel);
}
}
}
} // namespace shaka

View File

@ -10,7 +10,8 @@
#include <absl/flags/declare.h>
#include <absl/flags/flag.h>
// ABSL_DECLARE_FLAG(int32_t, v);
// ABSL_DECLARE_FLAG(std::string, vmodule);
namespace shaka {
void register_flags_with_glog();
}
#endif // APP_VLOG_FLAGS_H_