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

PiperOrigin-RevId: 633802444
  • Loading branch information
tanvi-jagtap authored and Copybara-Service committed May 15, 2024
1 parent befeeba commit cd34289
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/core/lib/surface/call.cc
Expand Up @@ -325,7 +325,7 @@ void Call::HandleCompressionAlgorithmDisabled(
grpc_compression_algorithm_name(compression_algorithm, &algo_name);
std::string error_msg =
absl::StrFormat("Compression algorithm '%s' is disabled.", algo_name);
gpr_log(GPR_ERROR, "%s", error_msg.c_str());
LOG(ERROR) << error_msg;
CancelWithError(grpc_error_set_int(absl::UnimplementedError(error_msg),
StatusIntProperty::kRpcStatus,
GRPC_STATUS_UNIMPLEMENTED));
Expand Down
7 changes: 4 additions & 3 deletions src/core/lib/surface/channel_init.cc
Expand Up @@ -27,6 +27,7 @@
#include <type_traits>

#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_join.h"
#include "absl/strings/string_view.h"
Expand Down Expand Up @@ -313,7 +314,7 @@ ChannelInit::StackConfig ChannelInit::BuildStackConfig(
const auto filter_str =
absl::StrCat(" ", loc_strs[filter.filter],
NameFromChannelFilter(filter.filter), after_str);
gpr_log(GPR_INFO, "%s", filter_str.c_str());
LOG(INFO) << filter_str;
}
// Finally list out the terminal filters and where they were registered
// from.
Expand All @@ -325,7 +326,7 @@ ChannelInit::StackConfig ChannelInit::BuildStackConfig(
strlen(NameFromChannelFilter(terminal.filter)),
' '),
"[terminal]");
gpr_log(GPR_INFO, "%s", filter_str.c_str());
LOG(INFO) << filter_str;
}
}
// Check if there are no terminal filters: this would be an error.
Expand Down Expand Up @@ -398,7 +399,7 @@ bool ChannelInit::CreateStack(ChannelStackBuilder* builder) const {
"\n");
}
}
gpr_log(GPR_ERROR, "%s", error.c_str());
LOG(ERROR) << error;
return false;
}
for (const auto& post_processor : stack_config.post_processors) {
Expand Down
9 changes: 5 additions & 4 deletions src/core/lib/surface/completion_queue.cc
Expand Up @@ -28,6 +28,7 @@
#include <vector>

#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/strings/str_format.h"
#include "absl/strings/str_join.h"
Expand Down Expand Up @@ -260,7 +261,7 @@ struct cq_next_data {
CHECK_EQ(queue.num_items(), 0);
#ifndef NDEBUG
if (pending_events.load(std::memory_order_acquire) != 0) {
gpr_log(GPR_ERROR, "Destroying CQ without draining it fully.");
LOG(ERROR) << "Destroying CQ without draining it fully.";
}
#endif
}
Expand Down Expand Up @@ -290,7 +291,7 @@ struct cq_pluck_data {
CHECK(completed_head.next == reinterpret_cast<uintptr_t>(&completed_head));
#ifndef NDEBUG
if (pending_events.load(std::memory_order_acquire) != 0) {
gpr_log(GPR_ERROR, "Destroying CQ without draining it fully.");
LOG(ERROR) << "Destroying CQ without draining it fully.";
}
#endif
}
Expand Down Expand Up @@ -327,7 +328,7 @@ struct cq_callback_data {
~cq_callback_data() {
#ifndef NDEBUG
if (pending_events.load(std::memory_order_acquire) != 0) {
gpr_log(GPR_ERROR, "Destroying CQ without draining it fully.");
LOG(ERROR) << "Destroying CQ without draining it fully.";
}
#endif
}
Expand Down Expand Up @@ -942,7 +943,7 @@ static void dump_pending_tags(grpc_completion_queue* cq) {
parts.push_back(absl::StrFormat(" %p", cq->outstanding_tags[i]));
}
gpr_mu_unlock(cq->mu);
gpr_log(GPR_DEBUG, "%s", absl::StrJoin(parts, "").c_str());
VLOG(2) << absl::StrJoin(parts, "");
}
#else
static void dump_pending_tags(grpc_completion_queue* /*cq*/) {}
Expand Down
9 changes: 5 additions & 4 deletions src/core/lib/surface/init.cc
Expand Up @@ -19,6 +19,7 @@
#include "src/core/lib/surface/init.h"

#include "absl/base/thread_annotations.h"
#include "absl/log/log.h"

#include <grpc/fork.h>
#include <grpc/grpc.h>
Expand Down Expand Up @@ -137,7 +138,7 @@ void grpc_shutdown_from_cleanup_thread(void* /*ignored*/) {
return;
}
grpc_shutdown_internal_locked();
gpr_log(GPR_DEBUG, "grpc_shutdown from cleanup thread done");
VLOG(2) << "grpc_shutdown from cleanup thread done";
}

void grpc_shutdown(void) {
Expand All @@ -155,14 +156,14 @@ void grpc_shutdown(void) {
0) &&
grpc_core::ExecCtx::Get() == nullptr) {
// just run clean-up when this is called on non-executor thread.
gpr_log(GPR_DEBUG, "grpc_shutdown starts clean-up now");
VLOG(2) << "grpc_shutdown starts clean-up now";
g_shutting_down = true;
grpc_shutdown_internal_locked();
gpr_log(GPR_DEBUG, "grpc_shutdown done");
VLOG(2) << "grpc_shutdown done";
} else {
// spawn a detached thread to do the actual clean up in case we are
// currently in an executor thread.
gpr_log(GPR_DEBUG, "grpc_shutdown spawns clean-up thread");
VLOG(2) << "grpc_shutdown spawns clean-up thread";
g_initializations++;
g_shutting_down = true;
grpc_core::Thread cleanup_thread(
Expand Down
5 changes: 3 additions & 2 deletions src/core/resolver/binder/binder_resolver.cc
Expand Up @@ -37,6 +37,7 @@
#include <memory>
#include <utility>

#include "absl/log/log.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
Expand Down Expand Up @@ -126,12 +127,12 @@ class BinderResolverFactory final : public ResolverFactory {
grpc_resolved_address addr;
{
if (!uri.authority().empty()) {
gpr_log(GPR_ERROR, "authority is not supported in binder scheme");
LOG(ERROR) << "authority is not supported in binder scheme";
return false;
}
grpc_error_handle error = BinderAddrPopulate(uri.path(), &addr);
if (!error.ok()) {
gpr_log(GPR_ERROR, "%s", StatusToString(error).c_str());
LOG(ERROR) << StatusToString(error);
return false;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/core/resolver/dns/c_ares/dns_resolver_ares.cc
Expand Up @@ -24,6 +24,7 @@
#include <vector>

#include "absl/base/thread_annotations.h"
#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/match.h"
Expand Down Expand Up @@ -348,7 +349,7 @@ class AresClientChannelDNSResolverFactory final : public ResolverFactory {

bool IsValidUri(const URI& uri) const override {
if (absl::StripPrefix(uri.path(), "/").empty()) {
gpr_log(GPR_ERROR, "no server name supplied in dns URI");
LOG(ERROR) << "no server name supplied in dns URI";
return false;
}
return true;
Expand Down
3 changes: 2 additions & 1 deletion src/core/resolver/dns/c_ares/grpc_ares_wrapper.cc
Expand Up @@ -19,6 +19,7 @@
#include <algorithm>
#include <vector>

#include "absl/log/log.h"
#include "absl/strings/string_view.h"

#include <grpc/impl/channel_arg_names.h>
Expand Down Expand Up @@ -952,7 +953,7 @@ static bool resolve_as_ip_literal_locked(
static bool target_matches_localhost_inner(const char* name, std::string* host,
std::string* port) {
if (!grpc_core::SplitHostPort(name, host, port)) {
gpr_log(GPR_ERROR, "Unable to split host and port for name: %s", name);
LOG(ERROR) << "Unable to split host and port for name: " << name;
return false;
}
return gpr_stricmp(host->c_str(), "localhost") == 0;
Expand Down
9 changes: 5 additions & 4 deletions src/core/resolver/dns/dns_resolver_plugin.cc
Expand Up @@ -15,6 +15,7 @@

#include <memory>

#include "absl/log/log.h"
#include "absl/strings/match.h"

#include <grpc/support/log.h>
Expand All @@ -32,14 +33,14 @@ namespace grpc_core {

void RegisterDnsResolver(CoreConfiguration::Builder* builder) {
#ifdef GRPC_IOS_EVENT_ENGINE_CLIENT
gpr_log(GPR_DEBUG, "Using EventEngine dns resolver");
VLOG(2) << "Using EventEngine dns resolver";
builder->resolver_registry()->RegisterResolverFactory(
std::make_unique<EventEngineClientChannelDNSResolverFactory>());
return;
#endif
#ifndef GRPC_DO_NOT_INSTANTIATE_POSIX_POLLER
if (IsEventEngineDnsEnabled()) {
gpr_log(GPR_DEBUG, "Using EventEngine dns resolver");
VLOG(2) << "Using EventEngine dns resolver";
builder->resolver_registry()->RegisterResolverFactory(
std::make_unique<EventEngineClientChannelDNSResolverFactory>());
return;
Expand All @@ -48,14 +49,14 @@ void RegisterDnsResolver(CoreConfiguration::Builder* builder) {
auto resolver = ConfigVars::Get().DnsResolver();
// ---- Ares resolver ----
if (ShouldUseAresDnsResolver(resolver)) {
gpr_log(GPR_DEBUG, "Using ares dns resolver");
VLOG(2) << "Using ares dns resolver";
RegisterAresDnsResolver(builder);
return;
}
// ---- Native resolver ----
if (absl::EqualsIgnoreCase(resolver, "native") ||
!builder->resolver_registry()->HasResolverFactory("dns")) {
gpr_log(GPR_DEBUG, "Using native dns resolver");
VLOG(2) << "Using native dns resolver";
RegisterNativeDnsResolver(builder);
return;
}
Expand Down
Expand Up @@ -26,6 +26,7 @@
#include "absl/base/thread_annotations.h"
#include "absl/cleanup/cleanup.h"
#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/match.h"
Expand Down Expand Up @@ -567,7 +568,7 @@ absl::optional<Resolver::Result> EventEngineClientChannelDNSResolver::
bool EventEngineClientChannelDNSResolverFactory::IsValidUri(
const URI& uri) const {
if (absl::StripPrefix(uri.path(), "/").empty()) {
gpr_log(GPR_ERROR, "no server name supplied in dns URI");
LOG(ERROR) << "no server name supplied in dns URI";
return false;
}
return true;
Expand Down
5 changes: 3 additions & 2 deletions src/core/resolver/dns/native/dns_resolver.cc
Expand Up @@ -20,6 +20,7 @@
#include <vector>

#include "absl/functional/bind_front.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 @@ -150,11 +151,11 @@ class NativeClientChannelDNSResolverFactory final : public ResolverFactory {

bool IsValidUri(const URI& uri) const override {
if (GPR_UNLIKELY(!uri.authority().empty())) {
gpr_log(GPR_ERROR, "authority based dns uri's not supported");
LOG(ERROR) << "authority based dns uri's not supported";
return false;
}
if (absl::StripPrefix(uri.path(), "/").empty()) {
gpr_log(GPR_ERROR, "no server name supplied in dns URI");
LOG(ERROR) << "no server name supplied in dns URI";
return false;
}
return true;
Expand Down
3 changes: 2 additions & 1 deletion src/core/resolver/google_c2p/google_c2p_resolver.cc
Expand Up @@ -22,6 +22,7 @@
#include <utility>

#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
Expand Down Expand Up @@ -282,7 +283,7 @@ class GoogleCloud2ProdResolverFactory final : public ResolverFactory {

bool IsValidUri(const URI& uri) const override {
if (GPR_UNLIKELY(!uri.authority().empty())) {
gpr_log(GPR_ERROR, "google-c2p URI scheme does not support authorities");
LOG(ERROR) << "google-c2p URI scheme does not support authorities";
return false;
}
return true;
Expand Down
5 changes: 3 additions & 2 deletions src/core/server/server.cc
Expand Up @@ -33,6 +33,7 @@
#include "absl/cleanup/cleanup.h"
#include "absl/container/flat_hash_map.h"
#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/types/optional.h"

Expand Down Expand Up @@ -980,7 +981,7 @@ grpc_error_handle Server::SetupTransport(
}
t->StartConnectivityWatch(MakeOrphanable<TransportConnectivityWatcher>(
t->RefAsSubclass<ServerTransport>(), Ref()));
gpr_log(GPR_INFO, "Adding connection");
LOG(INFO) << "Adding connection";
connections_.emplace(std::move(t));
++connections_open_;
} else {
Expand Down Expand Up @@ -1494,7 +1495,7 @@ void Server::ChannelData::Destroy() {
GRPC_CLOSURE_INIT(&finish_destroy_channel_closure_, FinishDestroy, this,
grpc_schedule_on_exec_ctx);
if (GRPC_TRACE_FLAG_ENABLED(grpc_server_channel_trace)) {
gpr_log(GPR_INFO, "Disconnected client");
LOG(INFO) << "Disconnected client";
}
grpc_transport_op* op =
grpc_make_transport_op(&finish_destroy_channel_closure_);
Expand Down
3 changes: 2 additions & 1 deletion src/core/service_config/service_config_channel_arg_filter.cc
Expand Up @@ -22,6 +22,7 @@
#include <string>
#include <utility>

#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/types/optional.h"
Expand Down Expand Up @@ -69,7 +70,7 @@ class ServiceConfigChannelArgFilter final
auto service_config =
ServiceConfigImpl::Create(args, *service_config_str);
if (!service_config.ok()) {
gpr_log(GPR_ERROR, "%s", service_config.status().ToString().c_str());
LOG(ERROR) << service_config.status().ToString();
} else {
service_config_ = std::move(*service_config);
}
Expand Down

0 comments on commit cd34289

Please sign in to comment.