From 4fb80e23ff6efe0135da87592d5203d36e7d64c7 Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Fri, 23 Aug 2024 16:18:22 -0700 Subject: [PATCH] [log] Fix logging for tests (#37560) This will fix timestamps on logs and show all `VLOG(2)` logs on tests by default. Currently, timestamps on logs are shown as - ``` I0000 00:00:1724385276.681936 1894892 config.cc:262] gRPC experiments enabled: call_tracer_in_transport, event_engine_dns, event_engine_listener, monitoring_experiment, pick_first_new, trace_record_callops, work_serializer_clears_time_cache ``` After invoking `absl::InitializeLog()`, this gets fixed to - ``` I0823 03:55:53.993928 1895644 config.cc:262] gRPC experiments enabled: call_tracer_in_transport, event_engine_dns, event_engine_listener, monitoring_experiment, pick_first_new, trace_record_callops, work_serializer_clears_time_cache ``` Closes #37560 COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/37560 from yashykt:ImproveLoggingForTests 66433336c87fe55981f978b79fb9c1669c08d4ea PiperOrigin-RevId: 666956421 --- CMakeLists.txt | 2 ++ build_autogenerated.yaml | 2 ++ test/core/test_util/BUILD | 2 ++ test/core/test_util/test_config.cc | 14 ++++++++++++++ 4 files changed, 20 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2be2bc1082f87d..ff82bc71644988 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2876,6 +2876,7 @@ target_link_libraries(grpc_test_util absl::failure_signal_handler absl::stacktrace absl::symbolize + absl::log_initialize grpc ) if(_gRPC_PLATFORM_IOS OR _gRPC_PLATFORM_MAC) @@ -2941,6 +2942,7 @@ target_link_libraries(grpc_test_util_unsecure absl::failure_signal_handler absl::stacktrace absl::symbolize + absl::log_initialize grpc_unsecure ) if(_gRPC_PLATFORM_IOS OR _gRPC_PLATFORM_MAC) diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index 7b2465e4c65498..74a7ec764a52a1 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -2122,6 +2122,7 @@ libs: - absl/debugging:failure_signal_handler - absl/debugging:stacktrace - absl/debugging:symbolize + - absl/log:initialize - grpc - name: grpc_test_util_unsecure build: private @@ -2150,6 +2151,7 @@ libs: - absl/debugging:failure_signal_handler - absl/debugging:stacktrace - absl/debugging:symbolize + - absl/log:initialize - grpc_unsecure - name: grpc_unsecure build: all diff --git a/test/core/test_util/BUILD b/test/core/test_util/BUILD index 347b06cb777029..12ae1064e45161 100644 --- a/test/core/test_util/BUILD +++ b/test/core/test_util/BUILD @@ -121,6 +121,7 @@ grpc_cc_library( "absl/debugging:failure_signal_handler", "absl/log:check", "absl/log:globals", + "absl/log:initialize", "absl/log:log", "absl/status", "absl/status:statusor", @@ -168,6 +169,7 @@ grpc_cc_library( external_deps = [ "absl/debugging:failure_signal_handler", "absl/log:check", + "absl/log:initialize", "absl/log:log", "absl/status", "absl/status:statusor", diff --git a/test/core/test_util/test_config.cc b/test/core/test_util/test_config.cc index 8ddb3c9b3cce25..1f428d557763fa 100644 --- a/test/core/test_util/test_config.cc +++ b/test/core/test_util/test_config.cc @@ -21,8 +21,11 @@ #include #include +#include + #include "absl/debugging/failure_signal_handler.h" #include "absl/log/globals.h" +#include "absl/log/initialize.h" #include "absl/log/log.h" #include "absl/status/status.h" #include "absl/strings/match.h" @@ -120,9 +123,20 @@ void ParseTestArgs(int* argc, char** argv) { ++i; } } + +// grpc-oss-only-begin +std::once_flag log_flag; +// grpc-oss-only-end + } // namespace void grpc_test_init(int* argc, char** argv) { + // grpc-oss-only-begin + std::call_once(log_flag, []() { absl::InitializeLog(); }); + absl::SetGlobalVLogLevel(2); + absl::SetMinLogLevel(absl::LogSeverityAtLeast::kInfo); + absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo); + // grpc-oss-only-end gpr_log_verbosity_init(); ParseTestArgs(argc, argv); grpc_core::testing::InitializeStackTracer(argv[0]);