[grpc][Gpr_To_Absl_Logging] Migrating from gpr to absl logging - 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.

PiperOrigin-RevId: 634278682
pull/36621/head
Tanvi Jagtap 7 months ago committed by Copybara-Service
parent 44e4bdc616
commit bb201db996
  1. 5
      src/core/lib/event_engine/ares_resolver.cc
  2. 9
      src/core/lib/event_engine/posix_engine/ev_epoll1_linux.cc
  3. 7
      src/core/lib/event_engine/posix_engine/posix_endpoint.cc
  4. 3
      src/core/lib/event_engine/posix_engine/posix_endpoint.h
  5. 3
      src/core/lib/event_engine/posix_engine/posix_engine.cc
  6. 5
      src/core/lib/event_engine/posix_engine/posix_engine_listener_utils.cc
  7. 5
      src/core/lib/event_engine/posix_engine/tcp_socket_utils.cc
  8. 3
      src/core/lib/event_engine/posix_engine/traced_buffer_list.cc
  9. 5
      src/core/lib/event_engine/thread_pool/work_stealing_thread_pool.cc

@ -53,6 +53,7 @@
#include "absl/functional/any_invocable.h" #include "absl/functional/any_invocable.h"
#include "absl/hash/hash.h" #include "absl/hash/hash.h"
#include "absl/log/check.h" #include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/strings/match.h" #include "absl/strings/match.h"
#include "absl/strings/numbers.h" #include "absl/strings/numbers.h"
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
@ -200,7 +201,7 @@ AresResolver::CreateAresResolver(
ares_channel channel; ares_channel channel;
int status = ares_init_options(&channel, &opts, ARES_OPT_FLAGS); int status = ares_init_options(&channel, &opts, ARES_OPT_FLAGS);
if (status != ARES_SUCCESS) { 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( return AresStatusToAbslStatus(
status, status,
absl::StrCat("Failed to init c-ares channel: ", ares_strerror(status))); absl::StrCat("Failed to init c-ares channel: ", ares_strerror(status)));
@ -769,7 +770,7 @@ void AresResolver::OnTXTDoneLocked(void* arg, int status, int /*timeouts*/,
result.size()); result.size());
if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_ares_resolver)) { if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_ares_resolver)) {
for (const auto& record : result) { for (const auto& record : result) {
gpr_log(GPR_INFO, "%s", record.c_str()); LOG(INFO) << record;
} }
} }
// Clean up. // Clean up.

@ -19,6 +19,7 @@
#include <memory> #include <memory>
#include "absl/log/check.h" #include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/status/status.h" #include "absl/status/status.h"
#include "absl/status/statusor.h" #include "absl/status/statusor.h"
#include "absl/strings/str_format.h" #include "absl/strings/str_format.h"
@ -164,14 +165,14 @@ int EpollCreateAndCloexec() {
#ifdef GRPC_LINUX_EPOLL_CREATE1 #ifdef GRPC_LINUX_EPOLL_CREATE1
int fd = epoll_create1(EPOLL_CLOEXEC); int fd = epoll_create1(EPOLL_CLOEXEC);
if (fd < 0) { if (fd < 0) {
gpr_log(GPR_ERROR, "epoll_create1 unavailable"); LOG(ERROR) << "epoll_create1 unavailable";
} }
#else #else
int fd = epoll_create(MAX_EPOLL_EVENTS); int fd = epoll_create(MAX_EPOLL_EVENTS);
if (fd < 0) { if (fd < 0) {
gpr_log(GPR_ERROR, "epoll_create unavailable"); LOG(ERROR) << "epoll_create unavailable";
} else if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) { } 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; return -1;
} }
#endif #endif
@ -356,7 +357,7 @@ Epoll1Poller::Epoll1Poller(Scheduler* scheduler)
wakeup_fd_ = *CreateWakeupFd(); wakeup_fd_ = *CreateWakeupFd();
CHECK(wakeup_fd_ != nullptr); CHECK(wakeup_fd_ != nullptr);
CHECK_GE(g_epoll_set_.epfd, 0); 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; struct epoll_event ev;
ev.events = static_cast<uint32_t>(EPOLLIN | EPOLLET); ev.events = static_cast<uint32_t>(EPOLLIN | EPOLLET);
ev.data.ptr = wakeup_fd_.get(); ev.data.ptr = wakeup_fd_.get();

@ -27,6 +27,7 @@
#include "absl/functional/any_invocable.h" #include "absl/functional/any_invocable.h"
#include "absl/log/check.h" #include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/status/status.h" #include "absl/status/status.h"
#include "absl/status/statusor.h" #include "absl/status/statusor.h"
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
@ -718,7 +719,7 @@ bool PosixEndpointImpl::ProcessErrors() {
return processed_err; return processed_err;
} }
if (GPR_UNLIKELY((msg.msg_flags & MSG_CTRUNC) != 0)) { 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) { if (msg.msg_controllen == 0) {
@ -813,7 +814,7 @@ struct cmsghdr* PosixEndpointImpl::ProcessTimestamp(msghdr* msg,
auto serr = reinterpret_cast<struct sock_extended_err*>(CMSG_DATA(next_cmsg)); auto serr = reinterpret_cast<struct sock_extended_err*>(CMSG_DATA(next_cmsg));
if (serr->ee_errno != ENOMSG || if (serr->ee_errno != ENOMSG ||
serr->ee_origin != SO_EE_ORIGIN_TIMESTAMPING) { serr->ee_origin != SO_EE_ORIGIN_TIMESTAMPING) {
gpr_log(GPR_ERROR, "Unexpected control message"); LOG(ERROR) << "Unexpected control message";
return cmsg; return cmsg;
} }
traced_buffers_.ProcessTimestamp(serr, opt_stats, tss); traced_buffers_.ProcessTimestamp(serr, opt_stats, tss);
@ -1303,7 +1304,7 @@ PosixEndpointImpl::PosixEndpointImpl(EventHandle* handle,
if (setsockopt(fd_, SOL_SOCKET, SO_ZEROCOPY, &enable, sizeof(enable)) != if (setsockopt(fd_, SOL_SOCKET, SO_ZEROCOPY, &enable, sizeof(enable)) !=
0) { 0) {
zerocopy_enabled = false; 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.";
} }
} }

@ -30,6 +30,7 @@
#include "absl/functional/any_invocable.h" #include "absl/functional/any_invocable.h"
#include "absl/hash/hash.h" #include "absl/hash/hash.h"
#include "absl/log/check.h" #include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/status/status.h" #include "absl/status/status.h"
#include "absl/status/statusor.h" #include "absl/status/statusor.h"
@ -183,7 +184,7 @@ class TcpZerocopySendCtx {
if (send_records_ == nullptr || free_send_records_ == nullptr) { if (send_records_ == nullptr || free_send_records_ == nullptr) {
gpr_free(send_records_); gpr_free(send_records_);
gpr_free(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; memory_limited_ = true;
enabled_ = false; enabled_ = false;
} else { } else {

@ -26,6 +26,7 @@
#include "absl/cleanup/cleanup.h" #include "absl/cleanup/cleanup.h"
#include "absl/functional/any_invocable.h" #include "absl/functional/any_invocable.h"
#include "absl/log/check.h" #include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/status/status.h" #include "absl/status/status.h"
#include "absl/strings/match.h" #include "absl/strings/match.h"
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
@ -231,7 +232,7 @@ void AsyncConnect::OnWritable(absl::Status status)
// your program or another program on the same computer // your program or another program on the same computer
// opened too many network connections. The "easy" fix: // opened too many network connections. The "easy" fix:
// don't do that! // don't do that!
gpr_log(GPR_ERROR, "kernel out of buffers"); LOG(ERROR) << "kernel out of buffers";
mu_.Unlock(); mu_.Unlock();
fd->NotifyOnWrite(on_writable_); fd->NotifyOnWrite(on_writable_);
// Don't run the cleanup function for this case. // Don't run the cleanup function for this case.

@ -23,6 +23,7 @@
#include "absl/cleanup/cleanup.h" #include "absl/cleanup/cleanup.h"
#include "absl/log/check.h" #include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/status/status.h" #include "absl/status/status.h"
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
#include "absl/strings/str_replace.h" #include "absl/strings/str_replace.h"
@ -156,7 +157,7 @@ absl::Status PrepareSocket(const PosixTcpOptions& options,
#ifdef GRPC_LINUX_ERRQUEUE #ifdef GRPC_LINUX_ERRQUEUE
if (!socket.sock.SetSocketZeroCopy().ok()) { if (!socket.sock.SetSocketZeroCopy().ok()) {
// it's not fatal, so just log it. // 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 { } else {
socket.zero_copy_enabled = true; socket.zero_copy_enabled = true;
} }
@ -244,7 +245,7 @@ absl::StatusOr<int> ListenerContainerAddAllLocalAddresses(
auto result = GetUnusedPort(); auto result = GetUnusedPort();
GRPC_RETURN_IF_ERROR(result.status()); GRPC_RETURN_IF_ERROR(result.status());
requested_port = *result; 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) { if (getifaddrs(&ifa) != 0 || ifa == nullptr) {
return absl::FailedPreconditionError( return absl::FailedPreconditionError(

@ -18,6 +18,7 @@
#include <limits.h> #include <limits.h>
#include "absl/cleanup/cleanup.h" #include "absl/cleanup/cleanup.h"
#include "absl/log/log.h"
#include "absl/status/statusor.h" #include "absl/status/statusor.h"
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
#include "absl/types/optional.h" #include "absl/types/optional.h"
@ -653,7 +654,7 @@ void PosixSocketWrapper::TrySetSocketTcpUserTimeout(
} }
if (newval != timeout) { if (newval != timeout) {
// Do not fail on failing to set TCP_USER_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; return;
} }
} }
@ -684,7 +685,7 @@ bool PosixSocketWrapper::IsIpv6LoopbackAvailable() {
int fd = socket(AF_INET6, SOCK_STREAM, 0); int fd = socket(AF_INET6, SOCK_STREAM, 0);
bool loopback_available = false; bool loopback_available = false;
if (fd < 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 { } else {
sockaddr_in6 addr; sockaddr_in6 addr;
memset(&addr, 0, sizeof(addr)); memset(&addr, 0, sizeof(addr));

@ -22,6 +22,7 @@
#include <utility> #include <utility>
#include "absl/functional/any_invocable.h" #include "absl/functional/any_invocable.h"
#include "absl/log/log.h"
#include <grpc/support/log.h> #include <grpc/support/log.h>
#include <grpc/support/port_platform.h> #include <grpc/support/port_platform.h>
@ -48,7 +49,7 @@ void FillGprFromTimestamp(gpr_timespec* gts, const struct timespec* ts) {
void DefaultTimestampsCallback(void* /*arg*/, Timestamps* /*ts*/, void DefaultTimestampsCallback(void* /*arg*/, Timestamps* /*ts*/,
absl::Status /*shudown_err*/) { 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 // The saved callback function that will be invoked when we get all the

@ -27,6 +27,7 @@
#include "absl/functional/any_invocable.h" #include "absl/functional/any_invocable.h"
#include "absl/log/check.h" #include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/time/clock.h" #include "absl/time/clock.h"
#include "absl/time/time.h" #include "absl/time/time.h"
#include "absl/types/optional.h" #include "absl/types/optional.h"
@ -267,7 +268,7 @@ void WorkStealingThreadPool::WorkStealingThreadPoolImpl::StartThread() {
} }
void WorkStealingThreadPool::WorkStealingThreadPoolImpl::Quiesce() { void WorkStealingThreadPool::WorkStealingThreadPoolImpl::Quiesce() {
gpr_log(GPR_INFO, "WorkStealingThreadPoolImpl::Quiesce"); LOG(INFO) << "WorkStealingThreadPoolImpl::Quiesce";
SetShutdown(true); SetShutdown(true);
// Wait until all threads have exited. // Wait until all threads have exited.
// Note that if this is a threadpool thread then we won't exit this thread // Note that if this is a threadpool thread then we won't exit this thread
@ -319,7 +320,7 @@ bool WorkStealingThreadPool::WorkStealingThreadPoolImpl::IsQuiesced() {
} }
void WorkStealingThreadPool::WorkStealingThreadPoolImpl::PrepareFork() { void WorkStealingThreadPool::WorkStealingThreadPoolImpl::PrepareFork() {
gpr_log(GPR_INFO, "WorkStealingThreadPoolImpl::PrepareFork"); LOG(INFO) << "WorkStealingThreadPoolImpl::PrepareFork";
SetForking(true); SetForking(true);
work_signal_.SignalAll(); work_signal_.SignalAll();
auto threads_were_shut_down = living_thread_count_.BlockUntilThreadCount( auto threads_were_shut_down = living_thread_count_.BlockUntilThreadCount(

Loading…
Cancel
Save