[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: 634277899
pull/36622/head
Tanvi Jagtap 9 months ago committed by Copybara-Service
parent c95886f65a
commit 44e4bdc616
  1. 3
      src/core/channelz/channelz_registry.cc
  2. 3
      src/core/client_channel/dynamic_filters.cc
  3. 3
      src/core/client_channel/subchannel.cc
  4. 3
      src/core/ext/filters/logging/logging_filter.cc
  5. 3
      src/core/ext/gcp/metadata_query.cc
  6. 1
      src/core/ext/transport/binder/client/channel_create.cc
  7. 3
      src/core/handshaker/http_connect/http_proxy_mapper.cc
  8. 11
      src/core/lib/address_utils/parse_address.cc
  9. 3
      src/core/lib/channel/channel_stack.cc
  10. 9
      src/core/lib/compression/message_compress.cc
  11. 5
      src/core/lib/debug/trace.cc
  12. 3
      src/core/lib/gprpp/posix/thd.cc
  13. 5
      src/core/lib/gprpp/windows/thd.cc
  14. 11
      src/core/lib/gprpp/work_serializer.cc
  15. 3
      src/core/lib/http/httpcli_security_connector.cc
  16. 5
      src/core/lib/promise/map_pipe.h
  17. 23
      src/core/lib/promise/pipe.h

@ -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>
@ -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;
}
}

@ -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>
@ -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);

@ -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"
@ -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);

@ -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"
@ -160,7 +161,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;
}

@ -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"
@ -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));

@ -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"

@ -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"
@ -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;

@ -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>
@ -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;
@ -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;
@ -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;
@ -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;
@ -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;

@ -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>
@ -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]" : "");

@ -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>
@ -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;
}
@ -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;
}
@ -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;
}

@ -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"
@ -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_;
}
}

@ -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>
@ -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

@ -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>
@ -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),

@ -28,6 +28,7 @@
#include "absl/container/inlined_vector.h"
#include "absl/log/check.h"
#include "absl/log/log.h"
#include <grpc/event_engine/event_engine.h>
#include <grpc/support/log.h>
@ -151,7 +152,7 @@ void WorkSerializer::LegacyWorkSerializer::Run(std::function<void()> callback,
// We took ownership of the WorkSerializer. Invoke callback and drain queue.
SetCurrentThread();
if (GRPC_TRACE_FLAG_ENABLED(grpc_work_serializer_trace)) {
gpr_log(GPR_INFO, " Executing immediately");
LOG(INFO) << " Executing immediately";
}
callback();
// Delete the callback while still holding the WorkSerializer, so
@ -193,7 +194,7 @@ void WorkSerializer::LegacyWorkSerializer::Orphan() {
refs_.fetch_sub(MakeRefPair(0, 1), std::memory_order_acq_rel);
if (GetOwners(prev_ref_pair) == 0 && GetSize(prev_ref_pair) == 1) {
if (GRPC_TRACE_FLAG_ENABLED(grpc_work_serializer_trace)) {
gpr_log(GPR_INFO, " Destroying");
LOG(INFO) << " Destroying";
}
delete this;
}
@ -232,7 +233,7 @@ void WorkSerializer::LegacyWorkSerializer::DrainQueueOwned() {
// up orphaning the work serializer. In that case, delete the object.
if (GetSize(prev_ref_pair) == 1) {
if (GRPC_TRACE_FLAG_ENABLED(grpc_work_serializer_trace)) {
gpr_log(GPR_INFO, " Queue Drained. Destroying");
LOG(INFO) << " Queue Drained. Destroying";
}
delete this;
return;
@ -252,7 +253,7 @@ void WorkSerializer::LegacyWorkSerializer::DrainQueueOwned() {
if (GetSize(expected) == 0) {
// WorkSerializer got orphaned while this was running
if (GRPC_TRACE_FLAG_ENABLED(grpc_work_serializer_trace)) {
gpr_log(GPR_INFO, " Queue Drained. Destroying");
LOG(INFO) << " Queue Drained. Destroying";
}
delete this;
return;
@ -272,7 +273,7 @@ void WorkSerializer::LegacyWorkSerializer::DrainQueueOwned() {
// This can happen due to a race condition within the mpscq
// implementation or because of a race with Run()/Schedule().
if (GRPC_TRACE_FLAG_ENABLED(grpc_work_serializer_trace)) {
gpr_log(GPR_INFO, " Queue returned nullptr, trying again");
LOG(INFO) << " Queue returned nullptr, trying again";
}
}
if (GRPC_TRACE_FLAG_ENABLED(grpc_work_serializer_trace)) {

@ -20,6 +20,7 @@
#include <string>
#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
@ -173,7 +174,7 @@ class HttpRequestSSLCredentials : public grpc_channel_credentials {
const tsi_ssl_root_certs_store* root_store =
DefaultSslRootStore::GetRootStore();
if (root_store == nullptr) {
gpr_log(GPR_ERROR, "Could not get default pem root certs.");
LOG(ERROR) << "Could not get default pem root certs.";
return nullptr;
}
absl::optional<std::string> target_string =

@ -15,6 +15,7 @@
#ifndef GRPC_SRC_CORE_LIB_PROMISE_MAP_PIPE_H
#define GRPC_SRC_CORE_LIB_PROMISE_MAP_PIPE_H
#include "absl/log/log.h"
#include "absl/status/status.h"
#include <grpc/support/log.h>
@ -46,14 +47,14 @@ auto MapPipe(PipeReceiver<T> src, PipeSender<T> dst, Filter filter_factory) {
return TrySeq(
[] {
if (grpc_trace_promise_primitives.enabled()) {
gpr_log(GPR_DEBUG, "MapPipe: start map");
VLOG(2) << "MapPipe: start map";
}
return Empty{};
},
filter_factory.Make(std::move(t)),
[&dst](T t) {
if (grpc_trace_promise_primitives.enabled()) {
gpr_log(GPR_DEBUG, "MapPipe: start push");
VLOG(2) << "MapPipe: start push";
}
return Map(dst.Push(std::move(t)), [](bool successful_push) {
if (successful_push) {

@ -23,6 +23,7 @@
#include <utility>
#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/strings/str_cat.h"
#include "absl/types/optional.h"
#include "absl/types/variant.h"
@ -119,7 +120,7 @@ class Center : public InterceptorList<T> {
// Add one ref to this object, and return this.
void IncrementRefCount() {
if (grpc_trace_promise_primitives.enabled()) {
gpr_log(GPR_DEBUG, "%s", DebugOpString("IncrementRefCount").c_str());
VLOG(2) << DebugOpString("IncrementRefCount");
}
refs_++;
DCHECK_NE(refs_, 0);
@ -134,7 +135,7 @@ class Center : public InterceptorList<T> {
// If no refs remain, destroy this object
void Unref() {
if (grpc_trace_promise_primitives.enabled()) {
gpr_log(GPR_DEBUG, "%s", DebugOpString("Unref").c_str());
VLOG(2) << DebugOpString("Unref");
}
DCHECK_GT(refs_, 0);
refs_--;
@ -149,7 +150,7 @@ class Center : public InterceptorList<T> {
// Return false if the recv end is closed.
Poll<bool> Push(T* value) {
if (grpc_trace_promise_primitives.enabled()) {
gpr_log(GPR_INFO, "%s", DebugOpString("Push").c_str());
LOG(INFO) << DebugOpString("Push");
}
DCHECK_NE(refs_, 0);
switch (value_state_) {
@ -173,7 +174,7 @@ class Center : public InterceptorList<T> {
Poll<bool> PollAck() {
if (grpc_trace_promise_primitives.enabled()) {
gpr_log(GPR_INFO, "%s", DebugOpString("PollAck").c_str());
LOG(INFO) << DebugOpString("PollAck");
}
DCHECK_NE(refs_, 0);
switch (value_state_) {
@ -201,7 +202,7 @@ class Center : public InterceptorList<T> {
// Return nullopt if the send end is closed and no value had been pushed.
Poll<absl::optional<T>> Next() {
if (grpc_trace_promise_primitives.enabled()) {
gpr_log(GPR_INFO, "%s", DebugOpString("Next").c_str());
LOG(INFO) << DebugOpString("Next");
}
DCHECK_NE(refs_, 0);
switch (value_state_) {
@ -227,7 +228,7 @@ class Center : public InterceptorList<T> {
// but the pipe is closed, reports closed).
Poll<bool> PollClosedForSender() {
if (grpc_trace_promise_primitives.enabled()) {
gpr_log(GPR_INFO, "%s", DebugOpString("PollClosedForSender").c_str());
LOG(INFO) << DebugOpString("PollClosedForSender");
}
DCHECK_NE(refs_, 0);
switch (value_state_) {
@ -250,7 +251,7 @@ class Center : public InterceptorList<T> {
// but the pipe is closed, reports open).
Poll<bool> PollClosedForReceiver() {
if (grpc_trace_promise_primitives.enabled()) {
gpr_log(GPR_INFO, "%s", DebugOpString("PollClosedForReceiver").c_str());
LOG(INFO) << DebugOpString("PollClosedForReceiver");
}
DCHECK_NE(refs_, 0);
switch (value_state_) {
@ -271,7 +272,7 @@ class Center : public InterceptorList<T> {
Poll<Empty> PollEmpty() {
if (grpc_trace_promise_primitives.enabled()) {
gpr_log(GPR_INFO, "%s", DebugOpString("PollEmpty").c_str());
LOG(INFO) << DebugOpString("PollEmpty");
}
DCHECK_NE(refs_, 0);
switch (value_state_) {
@ -291,7 +292,7 @@ class Center : public InterceptorList<T> {
void AckNext() {
if (grpc_trace_promise_primitives.enabled()) {
gpr_log(GPR_INFO, "%s", DebugOpString("AckNext").c_str());
LOG(INFO) << DebugOpString("AckNext");
}
switch (value_state_) {
case ValueState::kReady:
@ -318,7 +319,7 @@ class Center : public InterceptorList<T> {
void MarkClosed() {
if (grpc_trace_promise_primitives.enabled()) {
gpr_log(GPR_INFO, "%s", DebugOpString("MarkClosed").c_str());
LOG(INFO) << DebugOpString("MarkClosed");
}
switch (value_state_) {
case ValueState::kEmpty:
@ -347,7 +348,7 @@ class Center : public InterceptorList<T> {
void MarkCancelled() {
if (grpc_trace_promise_primitives.enabled()) {
gpr_log(GPR_INFO, "%s", DebugOpString("MarkCancelled").c_str());
LOG(INFO) << DebugOpString("MarkCancelled");
}
switch (value_state_) {
case ValueState::kEmpty:

Loading…
Cancel
Save