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

PiperOrigin-RevId: 633802446
  • Loading branch information
tanvi-jagtap authored and Copybara-Service committed May 15, 2024
1 parent befeeba commit 07c388e
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 18 deletions.
5 changes: 3 additions & 2 deletions src/core/lib/event_engine/ares_resolver.cc
Expand Up @@ -53,6 +53,7 @@
#include "absl/functional/any_invocable.h"
#include "absl/hash/hash.h"
#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/strings/match.h"
#include "absl/strings/numbers.h"
#include "absl/strings/str_cat.h"
Expand Down Expand Up @@ -200,7 +201,7 @@ AresResolver::CreateAresResolver(
ares_channel channel;
int status = ares_init_options(&channel, &opts, ARES_OPT_FLAGS);
if (status != ARES_SUCCESS) {
gpr_log(GPR_ERROR, "ares_init_options failed, status: %d", status);
LOG(ERROR) << "ares_init_options failed, status: " << status;
return AresStatusToAbslStatus(
status,
absl::StrCat("Failed to init c-ares channel: ", ares_strerror(status)));
Expand Down Expand Up @@ -769,7 +770,7 @@ void AresResolver::OnTXTDoneLocked(void* arg, int status, int /*timeouts*/,
result.size());
if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_ares_resolver)) {
for (const auto& record : result) {
gpr_log(GPR_INFO, "%s", record.c_str());
LOG(INFO) << record;
}
}
// Clean up.
Expand Down
9 changes: 5 additions & 4 deletions src/core/lib/event_engine/posix_engine/ev_epoll1_linux.cc
Expand Up @@ -19,6 +19,7 @@
#include <memory>

#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 @@ -164,14 +165,14 @@ int EpollCreateAndCloexec() {
#ifdef GRPC_LINUX_EPOLL_CREATE1
int fd = epoll_create1(EPOLL_CLOEXEC);
if (fd < 0) {
gpr_log(GPR_ERROR, "epoll_create1 unavailable");
LOG(ERROR) << "epoll_create1 unavailable";
}
#else
int fd = epoll_create(MAX_EPOLL_EVENTS);
if (fd < 0) {
gpr_log(GPR_ERROR, "epoll_create unavailable");
LOG(ERROR) << "epoll_create unavailable";
} else if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) {
gpr_log(GPR_ERROR, "fcntl following epoll_create failed");
LOG(ERROR) << "fcntl following epoll_create failed";
return -1;
}
#endif
Expand Down Expand Up @@ -356,7 +357,7 @@ Epoll1Poller::Epoll1Poller(Scheduler* scheduler)
wakeup_fd_ = *CreateWakeupFd();
CHECK(wakeup_fd_ != nullptr);
CHECK_GE(g_epoll_set_.epfd, 0);
gpr_log(GPR_INFO, "grpc epoll fd: %d", g_epoll_set_.epfd);
LOG(INFO) << "grpc epoll fd: " << g_epoll_set_.epfd;
struct epoll_event ev;
ev.events = static_cast<uint32_t>(EPOLLIN | EPOLLET);
ev.data.ptr = wakeup_fd_.get();
Expand Down
7 changes: 4 additions & 3 deletions src/core/lib/event_engine/posix_engine/posix_endpoint.cc
Expand Up @@ -27,6 +27,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/str_cat.h"
Expand Down Expand Up @@ -718,7 +719,7 @@ bool PosixEndpointImpl::ProcessErrors() {
return processed_err;
}
if (GPR_UNLIKELY((msg.msg_flags & MSG_CTRUNC) != 0)) {
gpr_log(GPR_ERROR, "Error message was truncated.");
LOG(ERROR) << "Error message was truncated.";
}

if (msg.msg_controllen == 0) {
Expand Down Expand Up @@ -813,7 +814,7 @@ struct cmsghdr* PosixEndpointImpl::ProcessTimestamp(msghdr* msg,
auto serr = reinterpret_cast<struct sock_extended_err*>(CMSG_DATA(next_cmsg));
if (serr->ee_errno != ENOMSG ||
serr->ee_origin != SO_EE_ORIGIN_TIMESTAMPING) {
gpr_log(GPR_ERROR, "Unexpected control message");
LOG(ERROR) << "Unexpected control message";
return cmsg;
}
traced_buffers_.ProcessTimestamp(serr, opt_stats, tss);
Expand Down Expand Up @@ -1303,7 +1304,7 @@ PosixEndpointImpl::PosixEndpointImpl(EventHandle* handle,
if (setsockopt(fd_, SOL_SOCKET, SO_ZEROCOPY, &enable, sizeof(enable)) !=
0) {
zerocopy_enabled = false;
gpr_log(GPR_ERROR, "Failed to set zerocopy options on the socket.");
LOG(ERROR) << "Failed to set zerocopy options on the socket.";
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/core/lib/event_engine/posix_engine/posix_endpoint.h
Expand Up @@ -30,6 +30,7 @@
#include "absl/functional/any_invocable.h"
#include "absl/hash/hash.h"
#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"

Expand Down Expand Up @@ -183,7 +184,7 @@ class TcpZerocopySendCtx {
if (send_records_ == nullptr || free_send_records_ == nullptr) {
gpr_free(send_records_);
gpr_free(free_send_records_);
gpr_log(GPR_INFO, "Disabling TCP TX zerocopy due to memory pressure.\n");
LOG(INFO) << "Disabling TCP TX zerocopy due to memory pressure.\n";
memory_limited_ = true;
enabled_ = false;
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/core/lib/event_engine/posix_engine/posix_engine.cc
Expand Up @@ -26,6 +26,7 @@
#include "absl/cleanup/cleanup.h"
#include "absl/functional/any_invocable.h"
#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/strings/match.h"
#include "absl/strings/str_cat.h"
Expand Down Expand Up @@ -231,7 +232,7 @@ void AsyncConnect::OnWritable(absl::Status status)
// 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";
mu_.Unlock();
fd->NotifyOnWrite(on_writable_);
// Don't run the cleanup function for this case.
Expand Down
Expand Up @@ -23,6 +23,7 @@

#include "absl/cleanup/cleanup.h"
#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_replace.h"
Expand Down Expand Up @@ -156,7 +157,7 @@ absl::Status PrepareSocket(const PosixTcpOptions& options,
#ifdef GRPC_LINUX_ERRQUEUE
if (!socket.sock.SetSocketZeroCopy().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.";
} else {
socket.zero_copy_enabled = true;
}
Expand Down Expand Up @@ -244,7 +245,7 @@ absl::StatusOr<int> ListenerContainerAddAllLocalAddresses(
auto result = GetUnusedPort();
GRPC_RETURN_IF_ERROR(result.status());
requested_port = *result;
gpr_log(GPR_DEBUG, "Picked unused port %d", requested_port);
VLOG(2) << "Picked unused port " << requested_port;
}
if (getifaddrs(&ifa) != 0 || ifa == nullptr) {
return absl::FailedPreconditionError(
Expand Down
5 changes: 3 additions & 2 deletions src/core/lib/event_engine/posix_engine/tcp_socket_utils.cc
Expand Up @@ -18,6 +18,7 @@
#include <limits.h>

#include "absl/cleanup/cleanup.h"
#include "absl/log/log.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
#include "absl/types/optional.h"
Expand Down Expand Up @@ -653,7 +654,7 @@ void PosixSocketWrapper::TrySetSocketTcpUserTimeout(
}
if (newval != timeout) {
// Do not fail on failing to set TCP_USER_TIMEOUT
gpr_log(GPR_ERROR, "Failed to set TCP_USER_TIMEOUT");
LOG(ERROR) << "Failed to set TCP_USER_TIMEOUT";
return;
}
}
Expand Down Expand Up @@ -684,7 +685,7 @@ bool PosixSocketWrapper::IsIpv6LoopbackAvailable() {
int fd = socket(AF_INET6, SOCK_STREAM, 0);
bool loopback_available = false;
if (fd < 0) {
gpr_log(GPR_INFO, "Disabling AF_INET6 sockets because socket() failed.");
LOG(INFO) << "Disabling AF_INET6 sockets because socket() failed.";
} else {
sockaddr_in6 addr;
memset(&addr, 0, sizeof(addr));
Expand Down
3 changes: 2 additions & 1 deletion src/core/lib/event_engine/posix_engine/traced_buffer_list.cc
Expand Up @@ -22,6 +22,7 @@
#include <utility>

#include "absl/functional/any_invocable.h"
#include "absl/log/log.h"

#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
Expand All @@ -48,7 +49,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 @@ -27,6 +27,7 @@

#include "absl/functional/any_invocable.h"
#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
#include "absl/types/optional.h"
Expand Down Expand Up @@ -267,7 +268,7 @@ void WorkStealingThreadPool::WorkStealingThreadPoolImpl::StartThread() {
}

void WorkStealingThreadPool::WorkStealingThreadPoolImpl::Quiesce() {
gpr_log(GPR_INFO, "WorkStealingThreadPoolImpl::Quiesce");
LOG(INFO) << "WorkStealingThreadPoolImpl::Quiesce";
SetShutdown(true);
// Wait until all threads have exited.
// Note that if this is a threadpool thread then we won't exit this thread
Expand Down Expand Up @@ -319,7 +320,7 @@ bool WorkStealingThreadPool::WorkStealingThreadPoolImpl::IsQuiesced() {
}

void WorkStealingThreadPool::WorkStealingThreadPoolImpl::PrepareFork() {
gpr_log(GPR_INFO, "WorkStealingThreadPoolImpl::PrepareFork");
LOG(INFO) << "WorkStealingThreadPoolImpl::PrepareFork";
SetForking(true);
work_signal_.SignalAll();
auto threads_were_shut_down = living_thread_count_.BlockUntilThreadCount(
Expand Down

0 comments on commit 07c388e

Please sign in to comment.