From ffe73d230c59e6c608feccc7acb70c5df83bce5b Mon Sep 17 00:00:00 2001 From: AJ Heller Date: Thu, 2 May 2024 11:44:00 -0700 Subject: [PATCH] [fix] Make GRPC_VERBOSITY=debug work with abseil logging (#36501) Closes #36501 COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/36501 from drfloob:make-debug-logging-work-again b5f81e4c394cfe957783e949ad73906933ea1a08 PiperOrigin-RevId: 630132023 --- BUILD | 1 + CMakeLists.txt | 11 ++++++----- build_autogenerated.yaml | 1 + gRPC-C++.podspec | 1 + gRPC-Core.podspec | 1 + src/core/lib/gpr/log.cc | 13 +++++++++++-- 6 files changed, 21 insertions(+), 7 deletions(-) diff --git a/BUILD b/BUILD index 73f2786a889..3f5dafb6c11 100644 --- a/BUILD +++ b/BUILD @@ -783,6 +783,7 @@ grpc_cc_library( "absl/base:log_severity", "absl/functional:any_invocable", "absl/log", + "absl/log:globals", "absl/memory", "absl/random", "absl/status", diff --git a/CMakeLists.txt b/CMakeLists.txt index 4afbf9c40e3..241894e54e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1749,6 +1749,7 @@ target_link_libraries(gpr absl::flags_marshalling absl::any_invocable absl::check + absl::log_globals absl::log absl::memory absl::random_random @@ -36925,7 +36926,7 @@ generate_pkgconfig( "gpr" "gRPC platform support library" "${gRPC_CORE_VERSION}" - "absl_any_invocable absl_base absl_check absl_cord absl_core_headers absl_flags absl_flags_marshalling absl_log absl_log_severity absl_memory absl_optional absl_random_random absl_status absl_str_format absl_strings absl_synchronization absl_time absl_variant" + "absl_any_invocable absl_base absl_check absl_cord absl_core_headers absl_flags absl_flags_marshalling absl_log absl_log_globals absl_log_severity absl_memory absl_optional absl_random_random absl_status absl_str_format absl_strings absl_synchronization absl_time absl_variant" "" "-lgpr" "" @@ -36936,7 +36937,7 @@ generate_pkgconfig( "gRPC" "high performance general RPC framework" "${gRPC_CORE_VERSION}" - "absl_algorithm_container absl_any_invocable absl_base absl_bind_front absl_check absl_cleanup absl_config absl_cord absl_core_headers absl_flags absl_flags_marshalling absl_flat_hash_map absl_flat_hash_set absl_function_ref absl_hash absl_inlined_vector absl_log absl_log_severity absl_memory absl_no_destructor absl_optional absl_random_bit_gen_ref absl_random_distributions absl_random_random absl_span absl_status absl_statusor absl_str_format absl_strings absl_synchronization absl_time absl_type_traits absl_utility absl_variant gpr" + "absl_algorithm_container absl_any_invocable absl_base absl_bind_front absl_check absl_cleanup absl_config absl_cord absl_core_headers absl_flags absl_flags_marshalling absl_flat_hash_map absl_flat_hash_set absl_function_ref absl_hash absl_inlined_vector absl_log absl_log_globals absl_log_severity absl_memory absl_no_destructor absl_optional absl_random_bit_gen_ref absl_random_distributions absl_random_random absl_span absl_status absl_statusor absl_str_format absl_strings absl_synchronization absl_time absl_type_traits absl_utility absl_variant gpr" "libcares openssl re2 zlib" "-lgrpc" "-laddress_sorting -lupb_textformat_lib -lupb_json_lib -lupb_message_lib -lupb_mem_lib -lupb_base_lib -lutf8_range_lib" @@ -36947,7 +36948,7 @@ generate_pkgconfig( "gRPC unsecure" "high performance general RPC framework without SSL" "${gRPC_CORE_VERSION}" - "absl_algorithm_container absl_any_invocable absl_base absl_bind_front absl_check absl_cleanup absl_config absl_cord absl_core_headers absl_flags absl_flags_marshalling absl_flat_hash_map absl_flat_hash_set absl_function_ref absl_hash absl_inlined_vector absl_log absl_log_severity absl_memory absl_no_destructor absl_optional absl_random_bit_gen_ref absl_random_distributions absl_random_random absl_span absl_status absl_statusor absl_str_format absl_strings absl_synchronization absl_time absl_type_traits absl_utility absl_variant gpr" + "absl_algorithm_container absl_any_invocable absl_base absl_bind_front absl_check absl_cleanup absl_config absl_cord absl_core_headers absl_flags absl_flags_marshalling absl_flat_hash_map absl_flat_hash_set absl_function_ref absl_hash absl_inlined_vector absl_log absl_log_globals absl_log_severity absl_memory absl_no_destructor absl_optional absl_random_bit_gen_ref absl_random_distributions absl_random_random absl_span absl_status absl_statusor absl_str_format absl_strings absl_synchronization absl_time absl_type_traits absl_utility absl_variant gpr" "libcares zlib" "-lgrpc_unsecure" "-laddress_sorting -lupb_message_lib -lupb_mem_lib -lupb_base_lib -lutf8_range_lib" @@ -36958,7 +36959,7 @@ generate_pkgconfig( "gRPC++" "C++ wrapper for gRPC" "${gRPC_CPP_VERSION}" - "absl_algorithm_container absl_any_invocable absl_base absl_bind_front absl_check absl_cleanup absl_config absl_cord absl_core_headers absl_flags absl_flags_marshalling absl_flat_hash_map absl_flat_hash_set absl_function_ref absl_hash absl_inlined_vector absl_log absl_log_severity absl_memory absl_no_destructor absl_optional absl_random_bit_gen_ref absl_random_distributions absl_random_random absl_span absl_status absl_statusor absl_str_format absl_strings absl_synchronization absl_time absl_type_traits absl_utility absl_variant gpr grpc" + "absl_algorithm_container absl_any_invocable absl_base absl_bind_front absl_check absl_cleanup absl_config absl_cord absl_core_headers absl_flags absl_flags_marshalling absl_flat_hash_map absl_flat_hash_set absl_function_ref absl_hash absl_inlined_vector absl_log absl_log_globals absl_log_severity absl_memory absl_no_destructor absl_optional absl_random_bit_gen_ref absl_random_distributions absl_random_random absl_span absl_status absl_statusor absl_str_format absl_strings absl_synchronization absl_time absl_type_traits absl_utility absl_variant gpr grpc" "libcares openssl re2 zlib" "-lgrpc++" "-laddress_sorting -lupb_textformat_lib -lupb_json_lib -lupb_message_lib -lupb_mem_lib -lupb_base_lib -lutf8_range_lib" @@ -36969,7 +36970,7 @@ generate_pkgconfig( "gRPC++ unsecure" "C++ wrapper for gRPC without SSL" "${gRPC_CPP_VERSION}" - "absl_algorithm_container absl_any_invocable absl_base absl_bind_front absl_check absl_cleanup absl_config absl_cord absl_core_headers absl_flags absl_flags_marshalling absl_flat_hash_map absl_flat_hash_set absl_function_ref absl_hash absl_inlined_vector absl_log absl_log_severity absl_memory absl_no_destructor absl_optional absl_random_bit_gen_ref absl_random_distributions absl_random_random absl_span absl_status absl_statusor absl_str_format absl_strings absl_synchronization absl_time absl_type_traits absl_utility absl_variant gpr grpc_unsecure" + "absl_algorithm_container absl_any_invocable absl_base absl_bind_front absl_check absl_cleanup absl_config absl_cord absl_core_headers absl_flags absl_flags_marshalling absl_flat_hash_map absl_flat_hash_set absl_function_ref absl_hash absl_inlined_vector absl_log absl_log_globals absl_log_severity absl_memory absl_no_destructor absl_optional absl_random_bit_gen_ref absl_random_distributions absl_random_random absl_span absl_status absl_statusor absl_str_format absl_strings absl_synchronization absl_time absl_type_traits absl_utility absl_variant gpr grpc_unsecure" "libcares zlib" "-lgrpc++_unsecure" "-laddress_sorting -lupb_message_lib -lupb_mem_lib -lupb_base_lib -lutf8_range_lib" diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index 0a60f89eb9a..725d1b1c622 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -130,6 +130,7 @@ libs: - absl/flags:marshalling - absl/functional:any_invocable - absl/log:check + - absl/log:globals - absl/log:log - absl/memory:memory - absl/random:random diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index c2faa4dd491..fc0b9d7b912 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -244,6 +244,7 @@ Pod::Spec.new do |s| ss.dependency 'abseil/functional/function_ref', abseil_version ss.dependency 'abseil/hash/hash', abseil_version ss.dependency 'abseil/log/check', abseil_version + ss.dependency 'abseil/log/globals', abseil_version ss.dependency 'abseil/log/log', abseil_version ss.dependency 'abseil/memory/memory', abseil_version ss.dependency 'abseil/meta/type_traits', abseil_version diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 7cf3df36551..892e42ba1b5 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -216,6 +216,7 @@ Pod::Spec.new do |s| ss.dependency 'abseil/functional/function_ref', abseil_version ss.dependency 'abseil/hash/hash', abseil_version ss.dependency 'abseil/log/check', abseil_version + ss.dependency 'abseil/log/globals', abseil_version ss.dependency 'abseil/log/log', abseil_version ss.dependency 'abseil/memory/memory', abseil_version ss.dependency 'abseil/meta/type_traits', abseil_version diff --git a/src/core/lib/gpr/log.cc b/src/core/lib/gpr/log.cc index 1755d99122d..38f1a4615c6 100644 --- a/src/core/lib/gpr/log.cc +++ b/src/core/lib/gpr/log.cc @@ -23,6 +23,7 @@ #include #include +#include "absl/log/globals.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" @@ -38,6 +39,7 @@ #define GPR_DEFAULT_LOG_VERBOSITY_STRING "ERROR" #endif // !GPR_DEFAULT_LOG_VERBOSITY_STRING +static constexpr int g_absl_vlog_level_for_gpr_verbosity_debug = 2; static constexpr gpr_atm GPR_LOG_SEVERITY_UNSET = GPR_LOG_SEVERITY_ERROR + 10; static constexpr gpr_atm GPR_LOG_SEVERITY_NONE = GPR_LOG_SEVERITY_ERROR + 11; @@ -83,8 +85,9 @@ void gpr_default_log(gpr_log_func_args* args) { } switch (args->severity) { case GPR_LOG_SEVERITY_DEBUG: - // Log DEBUG messages as VLOG(2). - VLOG(2).AtLocation(args->file, args->line) << args->message; + VLOG(g_absl_vlog_level_for_gpr_verbosity_debug) + .AtLocation(args->file, args->line) + << args->message; return; case GPR_LOG_SEVERITY_INFO: LOG(INFO).AtLocation(args->file, args->line) << args->message; @@ -145,6 +148,12 @@ void gpr_log_verbosity_init() { parse_log_severity(verbosity, min_severity_to_print); } gpr_atm_no_barrier_store(&g_min_severity_to_print, min_severity_to_print); + if (grpc_core::ConfigVars::Get().AbslLogging() && + min_severity_to_print == GPR_LOG_SEVERITY_DEBUG) { + // Matches full file paths that include a `*grpc*` folder, including + // grpcpp. + absl::SetVLogLevel("*grpc*/*", g_absl_vlog_level_for_gpr_verbosity_debug); + } } // init stacktrace_minloglevel when it hasn't been set if ((gpr_atm_no_barrier_load(&g_min_severity_to_print_stacktrace)) ==