diff --git a/packager/app/mpd_generator.cc b/packager/app/mpd_generator.cc index 1b6b50b2b9..b619435b85 100644 --- a/packager/app/mpd_generator.cc +++ b/packager/app/mpd_generator.cc @@ -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 @@ -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)); diff --git a/packager/app/packager_main.cc b/packager/app/packager_main.cc index 9c6004234c..0030e820f8 100644 --- a/packager/app/packager_main.cc +++ b/packager/app/packager_main.cc @@ -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 @@ -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()) { diff --git a/packager/app/vlog_flags.cc b/packager/app/vlog_flags.cc index 11c700f32d..496f2a9fd6 100644 --- a/packager/app/vlog_flags.cc +++ b/packager/app/vlog_flags.cc @@ -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. " " 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 +#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 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 diff --git a/packager/app/vlog_flags.h b/packager/app/vlog_flags.h index 7a430ce4da..66c8008ca2 100644 --- a/packager/app/vlog_flags.h +++ b/packager/app/vlog_flags.h @@ -10,7 +10,8 @@ #include #include -// ABSL_DECLARE_FLAG(int32_t, v); -// ABSL_DECLARE_FLAG(std::string, vmodule); +namespace shaka { +void register_flags_with_glog(); +} #endif // APP_VLOG_FLAGS_H_