Skip to content

Commit

Permalink
[log] Fix logging for tests (grpc#37560)
Browse files Browse the repository at this point in the history
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 grpc#37560

COPYBARA_INTEGRATE_REVIEW=grpc#37560 from yashykt:ImproveLoggingForTests 6643333
PiperOrigin-RevId: 666956421
  • Loading branch information
yashykt authored and paulosjca committed Aug 25, 2024
1 parent fa3807d commit 4fb80e2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions build_autogenerated.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions test/core/test_util/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions test/core/test_util/test_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
#include <inttypes.h>
#include <stdlib.h>

#include <mutex>

#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"
Expand Down Expand Up @@ -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]);
Expand Down

0 comments on commit 4fb80e2

Please sign in to comment.