Skip to content

Commit

Permalink
[export] [grpc][Gpr_To_Absl_Logging] Migrating from gpr to absl loggi…
Browse files Browse the repository at this point in the history
…ng - gpr_log

In this CL we are migrating from gRPCs own gpr logging mechanism to absl logging mechanism. The intention is to deprecate gpr_log in the future.
We have the following mapping
1. gpr_log(GPR_INFO,...) -> LOG(INFO)
2. gpr_log(GPR_ERROR,...) -> LOG(ERROR)
3. gpr_log(GPR_DEBUG,...) -> VLOG(2)
Reviewers need to check :
1. If the above mapping is correct.
2. The content of the log is as before.
gpr_log format strings did not use string_view or std::string . absl LOG accepts these. So there will be some elimination of string_view and std::string related conversions. This is expected.

----
DO NOT SUBMIT. This PR is for testing purposes only. [cl/633802448](http://cl/633802448)

PiperOrigin-RevId: 633802448
  • Loading branch information
tanvi-jagtap authored and Copybara-Service committed May 15, 2024
1 parent befeeba commit bef7149
Show file tree
Hide file tree
Showing 21 changed files with 69 additions and 45 deletions.
3 changes: 2 additions & 1 deletion src/core/channelz/channelz_registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <vector>

#include "absl/log/check.h"
#include "absl/log/log.h"

#include <grpc/grpc.h>
#include <grpc/support/json.h>
Expand Down Expand Up @@ -171,7 +172,7 @@ void ChannelzRegistry::InternalLogAllEntities() {
}
for (size_t i = 0; i < nodes.size(); ++i) {
std::string json = nodes[i]->RenderJsonString();
gpr_log(GPR_INFO, "%s", json.c_str());
LOG(INFO) << json;
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/core/client_channel/dynamic_filters.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <utility>

#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/status/statusor.h"

#include <grpc/support/log.h>
Expand Down Expand Up @@ -68,7 +69,7 @@ DynamicFilters::Call::Call(Args args, grpc_error_handle* error)
*error = grpc_call_stack_init(channel_stack_->channel_stack_.get(), 1,
Destroy, this, &call_args);
if (GPR_UNLIKELY(!error->ok())) {
gpr_log(GPR_ERROR, "error: %s", StatusToString(*error).c_str());
LOG(ERROR) << "error: " << StatusToString(*error);
return;
}
grpc_call_stack_set_pollset_or_pollset_set(call_stack, args.pollent);
Expand Down
3 changes: 2 additions & 1 deletion src/core/client_channel/subchannel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <utility>

#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/status/statusor.h"
#include "absl/strings/cord.h"
#include "absl/strings/str_cat.h"
Expand Down Expand Up @@ -196,7 +197,7 @@ SubchannelCall::SubchannelCall(Args args, grpc_error_handle* error)
*error = grpc_call_stack_init(connected_subchannel_->channel_stack(), 1,
SubchannelCall::Destroy, this, &call_args);
if (GPR_UNLIKELY(!error->ok())) {
gpr_log(GPR_ERROR, "error: %s", StatusToString(*error).c_str());
LOG(ERROR) << "error: " << StatusToString(*error);
return;
}
grpc_call_stack_set_pollset_or_pollset_set(callstk, args.pollent);
Expand Down
3 changes: 2 additions & 1 deletion src/core/ext/filters/logging/logging_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <utility>
#include <vector>

#include "absl/log/log.h"
#include "absl/numeric/int128.h"
#include "absl/random/random.h"
#include "absl/random/uniform_int_distribution.h"
Expand Down Expand Up @@ -157,7 +158,7 @@ LoggingSink::Entry::Address PeerStringToAddress(const Slice& peer_string) {
LoggingSink::Entry::Address address;
absl::StatusOr<URI> uri = URI::Parse(peer_string.as_string_view());
if (!uri.ok()) {
gpr_log(GPR_DEBUG, "peer_string is in invalid format and cannot be logged");
VLOG(2) << "peer_string is in invalid format and cannot be logged";
return address;
}

Expand Down
3 changes: 2 additions & 1 deletion src/core/ext/gcp/metadata_query.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <utility>

#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_format.h"
Expand Down Expand Up @@ -120,7 +121,7 @@ void MetadataQuery::OnDone(void* arg, grpc_error_handle error) {
absl::StrFormat("MetadataServer Could not parse zone: %s",
std::string(body).c_str()));
if (GRPC_TRACE_FLAG_ENABLED(grpc_metadata_query_trace)) {
gpr_log(GPR_INFO, "%s", result.status().ToString().c_str());
LOG(INFO) << result.status().ToString();
}
} else {
result = std::string(body.substr(pos + 1));
Expand Down
1 change: 1 addition & 0 deletions src/core/ext/transport/binder/client/channel_create.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#ifdef GPR_SUPPORT_BINDER_TRANSPORT

#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/memory/memory.h"
#include "absl/strings/substitute.h"
#include "absl/time/clock.h"
Expand Down
3 changes: 2 additions & 1 deletion src/core/handshaker/http_connect/http_proxy_mapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <utility>

#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/ascii.h"
Expand Down Expand Up @@ -150,7 +151,7 @@ absl::optional<std::string> GetHttpProxyServer(
// User cred found
*user_cred = authority_strs[0];
proxy_name = authority_strs[1];
gpr_log(GPR_DEBUG, "userinfo found in proxy URI");
VLOG(2) << "userinfo found in proxy URI";
} else {
// Bad authority
proxy_name = absl::nullopt;
Expand Down
11 changes: 6 additions & 5 deletions src/core/lib/address_utils/parse_address.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "src/core/lib/address_utils/parse_address.h"

#include "absl/log/check.h"
#include "absl/log/log.h"

#include <grpc/support/port_platform.h>

Expand Down Expand Up @@ -70,7 +71,7 @@ bool grpc_parse_unix(const grpc_core::URI& uri,
grpc_error_handle error =
grpc_core::UnixSockaddrPopulate(uri.path(), resolved_addr);
if (!error.ok()) {
gpr_log(GPR_ERROR, "%s", grpc_core::StatusToString(error).c_str());
LOG(ERROR) << "" << grpc_core::StatusToString(error);
return false;
}
return true;
Expand All @@ -86,7 +87,7 @@ bool grpc_parse_unix_abstract(const grpc_core::URI& uri,
grpc_error_handle error =
grpc_core::UnixAbstractSockaddrPopulate(uri.path(), resolved_addr);
if (!error.ok()) {
gpr_log(GPR_ERROR, "%s", grpc_core::StatusToString(error).c_str());
LOG(ERROR) << "" << grpc_core::StatusToString(error);
return false;
}
return true;
Expand Down Expand Up @@ -170,7 +171,7 @@ bool grpc_parse_vsock(const grpc_core::URI& uri,
grpc_error_handle error =
grpc_core::VSockaddrPopulate(uri.path(), resolved_addr);
if (!error.ok()) {
gpr_log(GPR_ERROR, "%s", grpc_core::StatusToString(error).c_str());
LOG(ERROR) << "" << grpc_core::StatusToString(error);
return false;
}
return true;
Expand Down Expand Up @@ -238,7 +239,7 @@ bool grpc_parse_ipv4_hostport(absl::string_view hostport,
}
// Parse port.
if (port.empty()) {
if (log_errors) gpr_log(GPR_ERROR, "no port given for ipv4 scheme");
if (log_errors) LOG(ERROR) << "no port given for ipv4 scheme";
goto done;
}
int port_num;
Expand Down Expand Up @@ -333,7 +334,7 @@ bool grpc_parse_ipv6_hostport(absl::string_view hostport,
}
// Parse port.
if (port.empty()) {
if (log_errors) gpr_log(GPR_ERROR, "no port given for ipv6 scheme");
if (log_errors) LOG(ERROR) << "no port given for ipv6 scheme";
goto done;
}
int port_num;
Expand Down
3 changes: 2 additions & 1 deletion src/core/lib/channel/channel_stack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <utility>

#include "absl/log/check.h"
#include "absl/log/log.h"

#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
Expand Down Expand Up @@ -121,7 +122,7 @@ grpc_error_handle grpc_channel_stack_init(
const grpc_core::ChannelArgs& channel_args, const char* name,
grpc_channel_stack* stack) {
if (grpc_trace_channel_stack.enabled()) {
gpr_log(GPR_INFO, "CHANNEL_STACK: init %s", name);
LOG(INFO) << "CHANNEL_STACK: init " << name;
for (size_t i = 0; i < filter_count; i++) {
gpr_log(GPR_INFO, "CHANNEL_STACK: filter %s%s", filters[i]->name,
filters[i]->make_call_promise ? " [promise-capable]" : "");
Expand Down
9 changes: 5 additions & 4 deletions src/core/lib/compression/message_compress.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <zlib.h>

#include "absl/log/check.h"
#include "absl/log/log.h"

#include <grpc/slice_buffer.h>
#include <grpc/support/alloc.h>
Expand Down Expand Up @@ -67,12 +68,12 @@ static int zlib_body(z_stream* zs, grpc_slice_buffer* input,
}
} while (zs->avail_out == 0);
if (zs->avail_in) {
gpr_log(GPR_INFO, "zlib: not all input consumed");
LOG(INFO) << "zlib: not all input consumed";
goto error;
}
}
if (r != Z_STREAM_END) {
gpr_log(GPR_INFO, "zlib: Data error");
LOG(INFO) << "zlib: Data error";
goto error;
}

Expand Down Expand Up @@ -165,7 +166,7 @@ static int compress_inner(grpc_compression_algorithm algorithm,
case GRPC_COMPRESS_ALGORITHMS_COUNT:
break;
}
gpr_log(GPR_ERROR, "invalid compression algorithm %d", algorithm);
LOG(ERROR) << "invalid compression algorithm " << algorithm;
return 0;
}

Expand All @@ -190,6 +191,6 @@ int grpc_msg_decompress(grpc_compression_algorithm algorithm,
case GRPC_COMPRESS_ALGORITHMS_COUNT:
break;
}
gpr_log(GPR_ERROR, "invalid compression algorithm %d", algorithm);
LOG(ERROR) << "invalid compression algorithm " << algorithm;
return 0;
}
5 changes: 3 additions & 2 deletions src/core/lib/debug/trace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <type_traits>
#include <utility>

#include "absl/log/log.h"
#include "absl/strings/match.h"
#include "absl/strings/str_split.h"
#include "absl/strings/string_view.h"
Expand Down Expand Up @@ -75,9 +76,9 @@ void TraceFlagList::Add(TraceFlag* flag) {
}

void TraceFlagList::LogAllTracers() {
gpr_log(GPR_DEBUG, "available tracers:");
VLOG(2) << "available tracers:";
for (TraceFlag* t = root_tracer_; t != nullptr; t = t->next_tracer_) {
gpr_log(GPR_DEBUG, "\t%s", t->name_);
VLOG(2) << "\t" << t->name_;
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/core/lib/gpr/linux/cpu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include <string.h>
#include <unistd.h>

#include "absl/log/log.h"

#include <grpc/support/cpu.h>
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
Expand All @@ -51,7 +53,7 @@ static void init_num_cpus() {
// determined
ncpus = static_cast<int>(sysconf(_SC_NPROCESSORS_CONF));
if (ncpus < 1) {
gpr_log(GPR_ERROR, "Cannot determine number of CPUs: assuming 1");
LOG(ERROR) << "Cannot determine number of CPUs: assuming 1";
ncpus = 1;
}
}
Expand All @@ -77,7 +79,7 @@ unsigned gpr_cpu_current_cpu(void) {
return 0;
}
if (static_cast<unsigned>(cpu) >= gpr_cpu_num_cores()) {
gpr_log(GPR_DEBUG, "Cannot handle hot-plugged CPUs");
VLOG(2) << "Cannot handle hot-plugged CPUs";
return 0;
}
return static_cast<unsigned>(cpu);
Expand Down
4 changes: 3 additions & 1 deletion src/core/lib/gpr/posix/cpu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include <string.h>
#include <unistd.h>

#include "absl/log/log.h"

#include <grpc/support/cpu.h>
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
Expand All @@ -39,7 +41,7 @@ static pthread_key_t thread_id_key;
static void init_ncpus() {
ncpus = sysconf(_SC_NPROCESSORS_CONF);
if (ncpus < 1 || ncpus > INT32_MAX) {
gpr_log(GPR_ERROR, "Cannot determine number of CPUs: assuming 1");
LOG(ERROR) << "Cannot determine number of CPUs: assuming 1";
ncpus = 1;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/core/lib/gpr/subprocess_windows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <tchar.h>
#include <windows.h>

#include "absl/log/log.h"
#include "absl/strings/str_join.h"
#include "absl/types/span.h"

Expand Down Expand Up @@ -114,7 +115,7 @@ void gpr_subprocess_interrupt(gpr_subprocess* p) {
DWORD dwExitCode;
if (GetExitCodeProcess(p->pi.hProcess, &dwExitCode)) {
if (dwExitCode == STILL_ACTIVE) {
gpr_log(GPR_INFO, "sending ctrl-break");
LOG(INFO) << "sending ctrl-break";
GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, p->pi.dwProcessId);
p->joined = 1;
p->interrupted = 1;
Expand Down
4 changes: 3 additions & 1 deletion src/core/lib/gpr/time_precise.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

#include <algorithm>

#include "absl/log/log.h" // IWYU pragma: keep

#include <grpc/support/log.h>
#include <grpc/support/time.h>

Expand Down Expand Up @@ -72,7 +74,7 @@ static bool is_fake_clock() {
}

void gpr_precise_clock_init(void) {
gpr_log(GPR_DEBUG, "Calibrating timers");
VLOG(2) << "Calibrating timers";

#if GPR_LINUX
if (read_freq_from_kernel(&cycles_per_second)) {
Expand Down
3 changes: 2 additions & 1 deletion src/core/lib/gprpp/posix/thd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <unistd.h>

#include "absl/log/check.h"
#include "absl/log/log.h" // IWYU pragma: keep

#include <grpc/support/log.h>
#include <grpc/support/sync.h>
Expand Down Expand Up @@ -213,7 +214,7 @@ void Thread::Kill(gpr_thd_id tid) {
}
#else // GPR_ANDROID
void Thread::Kill(gpr_thd_id /* tid */) {
gpr_log(GPR_DEBUG, "Thread::Kill is not supported on Android.");
VLOG(2) << "Thread::Kill is not supported on Android.";
}
#endif

Expand Down
5 changes: 3 additions & 2 deletions src/core/lib/gprpp/windows/thd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <string.h>

#include "absl/log/check.h"
#include "absl/log/log.h"

#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
Expand Down Expand Up @@ -149,12 +150,12 @@ namespace grpc_core {

void Thread::Signal(gpr_thd_id /* tid */, int /* sig */) {
// TODO(hork): Implement
gpr_log(GPR_DEBUG, "Thread signals are not supported on Windows.");
VLOG(2) << "Thread signals are not supported on Windows.";
}

void Thread::Kill(gpr_thd_id /* tid */) {
// TODO(hork): Implement
gpr_log(GPR_DEBUG, "Thread::Kill is not supported on Windows.");
VLOG(2) << "Thread::Kill is not supported on Windows.";
}

Thread::Thread(const char* /* thd_name */, void (*thd_body)(void* arg),
Expand Down

0 comments on commit bef7149

Please sign in to comment.