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/633802445](http://cl/633802445)

PiperOrigin-RevId: 633802445
  • Loading branch information
tanvi-jagtap authored and Copybara-Service committed May 15, 2024
1 parent befeeba commit 6cc2ebb
Show file tree
Hide file tree
Showing 17 changed files with 61 additions and 41 deletions.
6 changes: 4 additions & 2 deletions src/core/lib/iomgr/buffer_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include "src/core/lib/iomgr/buffer_list.h"

#include "absl/log/log.h"

#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
#include <grpc/support/time.h>
Expand All @@ -42,7 +44,7 @@ void FillGprFromTimestamp(gpr_timespec* gts, const struct timespec* ts) {

void DefaultTimestampsCallback(void* /*arg*/, Timestamps* /*ts*/,
absl::Status /*shudown_err*/) {
gpr_log(GPR_DEBUG, "Timestamps callback has not been registered");
VLOG(2) << "Timestamps callback has not been registered";
}

// The saved callback function that will be invoked when we get all the
Expand Down Expand Up @@ -321,7 +323,7 @@ void grpc_tcp_set_write_timestamps_callback(
// Can't comment out the name because some compilers and formatters don't
// like the sequence */* , which would arise from */*fn*/.
(void)fn;
gpr_log(GPR_DEBUG, "Timestamps callback is not enabled for this platform");
VLOG(2) << "Timestamps callback is not enabled for this platform";
}
} // namespace grpc_core

Expand Down
11 changes: 6 additions & 5 deletions src/core/lib/iomgr/call_combiner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <inttypes.h>

#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 @@ -130,13 +131,13 @@ void CallCombiner::Start(grpc_closure* closure, grpc_error_handle error,
}
if (prev_size == 0) {
if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) {
gpr_log(GPR_INFO, " EXECUTING IMMEDIATELY");
LOG(INFO) << " EXECUTING IMMEDIATELY";
}
// Queue was empty, so execute this closure immediately.
ScheduleClosure(closure, error);
} else {
if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) {
gpr_log(GPR_INFO, " QUEUING");
LOG(INFO) << " QUEUING";
}
// Queue was not empty, so add closure to queue.
closure->error_data.error = internal::StatusAllocHeapPtr(error);
Expand All @@ -160,7 +161,7 @@ void CallCombiner::Stop(DEBUG_ARGS const char* reason) {
if (prev_size > 1) {
while (true) {
if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) {
gpr_log(GPR_INFO, " checking queue");
LOG(INFO) << " checking queue";
}
bool empty;
grpc_closure* closure =
Expand All @@ -169,7 +170,7 @@ void CallCombiner::Stop(DEBUG_ARGS const char* reason) {
// This can happen either due to a race condition within the mpscq
// code or because of a race with Start().
if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) {
gpr_log(GPR_INFO, " queue returned no result; checking again");
LOG(INFO) << " queue returned no result; checking again";
}
continue;
}
Expand All @@ -184,7 +185,7 @@ void CallCombiner::Stop(DEBUG_ARGS const char* reason) {
break;
}
} else if (GRPC_TRACE_FLAG_ENABLED(grpc_call_combiner_trace)) {
gpr_log(GPR_INFO, " queue empty");
LOG(INFO) << " queue empty";
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/core/lib/iomgr/ev_epoll1_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
//

#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 @@ -122,7 +123,7 @@ static bool epoll_set_init() {
return false;
}

gpr_log(GPR_INFO, "grpc epoll fd: %d", g_epoll_set.epfd);
LOG(INFO) << "grpc epoll fd: " << g_epoll_set.epfd;
gpr_atm_no_barrier_store(&g_epoll_set.num_events, 0);
gpr_atm_no_barrier_store(&g_epoll_set.cursor, 0);
return true;
Expand Down Expand Up @@ -1073,7 +1074,7 @@ static grpc_error_handle pollset_kick(grpc_pollset* pollset,
log.push_back(absl::StrFormat(" worker_kick_state=%s",
kick_state_string(specific_worker->state)));
}
gpr_log(GPR_DEBUG, "%s", absl::StrJoin(log, "").c_str());
VLOG(2) << absl::StrJoin(log, "");
}

if (specific_worker == nullptr) {
Expand Down
7 changes: 4 additions & 3 deletions src/core/lib/iomgr/ev_poll_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <string>

#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"

Expand Down Expand Up @@ -583,7 +584,7 @@ static void fd_notify_on_write(grpc_fd* fd, grpc_closure* closure) {

static void fd_notify_on_error(grpc_fd* /*fd*/, grpc_closure* closure) {
if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_ERROR, "Polling engine does not support tracking errors.");
LOG(ERROR) << "Polling engine does not support tracking errors.";
}
grpc_core::ExecCtx::Run(DEBUG_LOCATION, closure, absl::CancelledError());
}
Expand All @@ -602,7 +603,7 @@ static void fd_set_writable(grpc_fd* fd) {

static void fd_set_error(grpc_fd* /*fd*/) {
if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_ERROR, "Polling engine does not support tracking errors.");
LOG(ERROR) << "Polling engine does not support tracking errors.";
}
}

Expand Down Expand Up @@ -1397,7 +1398,7 @@ const grpc_event_engine_vtable grpc_ev_poll_posix = {
// check_engine_available =
[](bool) {
if (!grpc_has_wakeup_fd()) {
gpr_log(GPR_ERROR, "Skipping poll because of no wakeup fd.");
LOG(ERROR) << "Skipping poll because of no wakeup fd.";
return false;
}
if (!GRPC_LOG_IF_ERROR("pollset_global_init", pollset_global_init())) {
Expand Down
3 changes: 2 additions & 1 deletion src/core/lib/iomgr/ev_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <string.h>

#include "absl/log/log.h"
#include "absl/strings/str_format.h"
#include "absl/strings/str_split.h"

Expand Down Expand Up @@ -109,7 +110,7 @@ static void try_engine(absl::string_view engine) {
if (g_vtables[i] != nullptr && is(engine, g_vtables[i]->name) &&
g_vtables[i]->check_engine_available(engine == g_vtables[i]->name)) {
g_event_engine = g_vtables[i];
gpr_log(GPR_DEBUG, "Using polling engine: %s", g_event_engine->name);
VLOG(2) << "Using polling engine: " << g_event_engine->name;
return;
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/core/lib/iomgr/event_engine_shims/endpoint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "absl/functional/any_invocable.h"
#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/string_view.h"
Expand Down Expand Up @@ -128,7 +129,7 @@ class EventEngineEndpointWrapper {
for (i = 0; i < pending_read_buffer_->count; i++) {
char* dump = grpc_dump_slice(pending_read_buffer_->slices[i],
GPR_DUMP_HEX | GPR_DUMP_ASCII);
gpr_log(GPR_DEBUG, "READ DATA: %s", dump);
VLOG(2) << "READ DATA: " << dump;
gpr_free(dump);
}
}
Expand Down Expand Up @@ -159,7 +160,7 @@ class EventEngineEndpointWrapper {
for (i = 0; i < slices->count; i++) {
char* dump =
grpc_dump_slice(slices->slices[i], GPR_DUMP_HEX | GPR_DUMP_ASCII);
gpr_log(GPR_DEBUG, "WRITE DATA: %s", dump);
VLOG(2) << "WRITE DATA: " << dump;
gpr_free(dump);
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/core/lib/iomgr/fork_windows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#ifndef GRPC_POSIX_FORK

#include "absl/log/log.h"

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

Expand All @@ -30,7 +32,7 @@
// AROUND VERY SPECIFIC USE CASES.
//

void grpc_prefork() { gpr_log(GPR_ERROR, "Forking not supported on Windows"); }
void grpc_prefork() { LOG(ERROR) << "Forking not supported on Windows"; }

void grpc_postfork_parent() {}

Expand Down
6 changes: 4 additions & 2 deletions src/core/lib/iomgr/internal_errqueue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "src/core/lib/iomgr/internal_errqueue.h"

#include "absl/log/log.h"

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

Expand All @@ -37,7 +39,7 @@ bool KernelSupportsErrqueue() {
// least 4.0.0
struct utsname buffer;
if (uname(&buffer) != 0) {
gpr_log(GPR_ERROR, "uname: %s", StrError(errno).c_str());
LOG(ERROR) << "uname: " << StrError(errno);
return false;
}
char* release = buffer.release;
Expand All @@ -48,7 +50,7 @@ bool KernelSupportsErrqueue() {
if (strtol(release, nullptr, 10) >= 4) {
return true;
} else {
gpr_log(GPR_DEBUG, "ERRQUEUE support not enabled");
VLOG(2) << "ERRQUEUE support not enabled";
}
#endif // GRPC_LINUX_ERRQUEUE
return false;
Expand Down
3 changes: 2 additions & 1 deletion src/core/lib/iomgr/iocp_windows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <limits>

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

#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
Expand Down Expand Up @@ -157,7 +158,7 @@ void grpc_iocp_add_socket(grpc_winsocket* socket) {
(uintptr_t)socket, 0);
if (!ret) {
char* utf8_message = gpr_format_message(WSAGetLastError());
gpr_log(GPR_ERROR, "Unable to add socket to iocp: %s", utf8_message);
LOG(ERROR) << "Unable to add socket to iocp: " << utf8_message;
gpr_free(utf8_message);
__debugbreak();
abort();
Expand Down
5 changes: 3 additions & 2 deletions src/core/lib/iomgr/socket_utils_common_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <string>

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

#include <grpc/event_engine/endpoint_config.h>
#include <grpc/support/alloc.h>
Expand Down Expand Up @@ -411,7 +412,7 @@ grpc_error_handle grpc_set_socket_tcp_user_timeout(
}
} else {
if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
gpr_log(GPR_INFO, "TCP_USER_TIMEOUT not supported for this platform");
LOG(INFO) << "TCP_USER_TIMEOUT not supported for this platform";
}
}
return absl::OkStatus();
Expand Down Expand Up @@ -442,7 +443,7 @@ static void probe_ipv6_once(void) {
int fd = socket(AF_INET6, SOCK_STREAM, 0);
g_ipv6_loopback_available = 0;
if (fd < 0) {
gpr_log(GPR_INFO, "Disabling AF_INET6 sockets because socket() failed.");
LOG(INFO) << "Disabling AF_INET6 sockets because socket() failed.";
} else {
grpc_sockaddr_in6 addr;
memset(&addr, 0, sizeof(addr));
Expand Down
3 changes: 2 additions & 1 deletion src/core/lib/iomgr/socket_windows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <mswsock.h>

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

#include <grpc/support/alloc.h>
Expand Down Expand Up @@ -217,7 +218,7 @@ static void probe_ipv6_once(void) {
SOCKET s = socket(AF_INET6, SOCK_STREAM, 0);
g_ipv6_loopback_available = 0;
if (s == INVALID_SOCKET) {
gpr_log(GPR_INFO, "Disabling AF_INET6 sockets because socket() failed.");
LOG(INFO) << "Disabling AF_INET6 sockets because socket() failed.";
} else {
grpc_sockaddr_in6 addr;
memset(&addr, 0, sizeof(addr));
Expand Down
3 changes: 2 additions & 1 deletion src/core/lib/iomgr/tcp_client_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "absl/container/flat_hash_map.h"
#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/strings/str_cat.h"

#include <grpc/support/alloc.h>
Expand Down Expand Up @@ -240,7 +241,7 @@ static void on_writable(void* acp, grpc_error_handle error) {
// your program or another program on the same computer
// opened too many network connections. The "easy" fix:
// don't do that!
gpr_log(GPR_ERROR, "kernel out of buffers");
LOG(ERROR) << "kernel out of buffers";
gpr_mu_unlock(&ac->mu);
grpc_fd_notify_on_write(fd, &ac->write_closure);
return;
Expand Down
9 changes: 5 additions & 4 deletions src/core/lib/iomgr/tcp_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
//

#include "absl/base/thread_annotations.h"
#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
Expand Down Expand Up @@ -875,7 +876,7 @@ static void tcp_trace_read(grpc_tcp* tcp, grpc_error_handle error)
for (i = 0; i < tcp->incoming_buffer->count; i++) {
char* dump = grpc_dump_slice(tcp->incoming_buffer->slices[i],
GPR_DUMP_HEX | GPR_DUMP_ASCII);
gpr_log(GPR_DEBUG, "READ DATA: %s", dump);
VLOG(2) << "READ DATA: " << dump;
gpr_free(dump);
}
}
Expand Down Expand Up @@ -1853,7 +1854,7 @@ static void tcp_handle_write(void* arg /* grpc_tcp */,
tcp->write_cb = nullptr;
tcp->current_zerocopy_send = nullptr;
if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
gpr_log(GPR_INFO, "write: %s", grpc_core::StatusToString(error).c_str());
LOG(INFO) << "write: " << grpc_core::StatusToString(error);
}
// No need to take a ref on error since tcp_flush provides a ref.
grpc_core::Closure::Run(DEBUG_LOCATION, cb, error);
Expand All @@ -1877,7 +1878,7 @@ static void tcp_write(grpc_endpoint* ep, grpc_slice_buffer* buf,
if (gpr_should_log(GPR_LOG_SEVERITY_DEBUG)) {
char* data =
grpc_dump_slice(buf->slices[i], GPR_DUMP_HEX | GPR_DUMP_ASCII);
gpr_log(GPR_DEBUG, "WRITE DATA: %s", data);
VLOG(2) << "WRITE DATA: " << data;
gpr_free(data);
}
}
Expand Down Expand Up @@ -1921,7 +1922,7 @@ static void tcp_write(grpc_endpoint* ep, grpc_slice_buffer* buf,
notify_on_write(tcp);
} else {
if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) {
gpr_log(GPR_INFO, "write: %s", grpc_core::StatusToString(error).c_str());
LOG(INFO) << "write: " << grpc_core::StatusToString(error);
}
grpc_core::Closure::Run(DEBUG_LOCATION, cb, error);
}
Expand Down
3 changes: 2 additions & 1 deletion src/core/lib/iomgr/tcp_server_utils_posix_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <string>

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

#include <grpc/support/alloc.h>
Expand Down Expand Up @@ -221,7 +222,7 @@ grpc_error_handle grpc_tcp_server_prepare_socket(
err = grpc_set_socket_zerocopy(fd);
if (!err.ok()) {
// it's not fatal, so just log it.
gpr_log(GPR_DEBUG, "Node does not support SO_ZEROCOPY, continuing.");
VLOG(2) << "Node does not support SO_ZEROCOPY, continuing.";
}
#endif
err = grpc_set_socket_nonblocking(fd, 1);
Expand Down
3 changes: 2 additions & 1 deletion src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <string>

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

#include <grpc/support/alloc.h>
Expand Down Expand Up @@ -115,7 +116,7 @@ grpc_error_handle grpc_tcp_server_add_all_local_addrs(grpc_tcp_server* s,
} else if (requested_port <= 0) {
return GRPC_ERROR_CREATE("Bad get_unused_port()");
}
gpr_log(GPR_DEBUG, "Picked unused port %d", requested_port);
VLOG(2) << "Picked unused port " << requested_port;
}

static bool v4_available = grpc_is_ipv4_availabile();
Expand Down

0 comments on commit 6cc2ebb

Please sign in to comment.