[grpc][Gpr_To_Absl_Logging] Migrating from gpr to absl logging - gpr_log

pull/36594/head
tanvi-jagtap 10 months ago
parent 69237b6786
commit 969cd32c41
  1. 28
      src/cpp/ext/gcp/observability_logging_sink.cc
  2. 37
      src/cpp/server/server_builder.cc
  3. 3
      src/cpp/server/server_cc.cc

@ -360,22 +360,20 @@ void ObservabilityLoggingSink::FlushEntriesHelper(
&(call->context), &(call->request), &(call->response),
[this, call](Status status) {
if (!status.ok()) {
gpr_log(
GPR_ERROR,
"GCP Observability Logging Error %d: %s. Dumping log entries.",
status.error_code(), status.error_message().c_str());
LOG(ERROR) << "GCP Observability Logging Error "
<< status.error_code() << ": " << status.error_message()
<< ". Dumping log entries.";
for (auto& entry : call->request.entries()) {
std::string output;
::google::protobuf::TextFormat::PrintToString(entry.json_payload(),
&output);
gpr_log(
GPR_INFO, "Log Entry recorded at time: %s : %s",
grpc_core::Timestamp::FromTimespecRoundUp(
gpr_timespec{entry.timestamp().seconds(),
entry.timestamp().nanos(), GPR_CLOCK_REALTIME})
.ToString()
.c_str(),
output.c_str());
LOG(INFO) << "Log Entry recorded at time: "
<< grpc_core::Timestamp::FromTimespecRoundUp(
gpr_timespec{entry.timestamp().seconds(),
entry.timestamp().nanos(),
GPR_CLOCK_REALTIME})
.ToString()
<< " : " << output;
}
}
delete call;
@ -414,7 +412,7 @@ void ObservabilityLoggingSink::MaybeTriggerFlushLocked() {
if (entries_.empty()) return;
if (entries_.size() > kMaxEntriesBeforeDump ||
entries_memory_footprint_ > kMaxMemoryFootprintBeforeDump) {
// Buffer limits have been reached. Dump entries with gpr_log
// Buffer limits have been reached. Dump entries with LOG
LOG(INFO) << "Buffer limit reached. Dumping log entries.";
for (auto& entry : entries_) {
google::protobuf::Struct proto;
@ -422,8 +420,8 @@ void ObservabilityLoggingSink::MaybeTriggerFlushLocked() {
EntryToJsonStructProto(std::move(entry), &proto);
std::string output;
::google::protobuf::TextFormat::PrintToString(proto, &output);
gpr_log(GPR_INFO, "Log Entry recorded at time: %s : %s",
timestamp.c_str(), output.c_str());
LOG(INFO) << "Log Entry recorded at time: " << timestamp << " : "
<< output;
}
entries_.clear();
entries_memory_footprint_ = 0;

@ -139,10 +139,9 @@ ServerBuilder& ServerBuilder::RegisterService(const std::string& host,
ServerBuilder& ServerBuilder::RegisterAsyncGenericService(
AsyncGenericService* service) {
if (generic_service_ || callback_generic_service_) {
gpr_log(GPR_ERROR,
"Adding multiple generic services is unsupported for now. "
"Dropping the service %p",
service);
LOG(ERROR) << "Adding multiple generic services is unsupported for now. "
"Dropping the service "
<< service;
} else {
generic_service_ = service;
}
@ -152,10 +151,9 @@ ServerBuilder& ServerBuilder::RegisterAsyncGenericService(
ServerBuilder& ServerBuilder::RegisterCallbackGenericService(
CallbackGenericService* service) {
if (generic_service_ || callback_generic_service_) {
gpr_log(GPR_ERROR,
"Adding multiple generic services is unsupported for now. "
"Dropping the service %p",
service);
LOG(ERROR) << "Adding multiple generic services is unsupported for now. "
"Dropping the service "
<< service;
} else {
callback_generic_service_ = service;
}
@ -391,12 +389,12 @@ std::unique_ptr<grpc::Server> ServerBuilder::BuildAndStart() {
if (has_sync_methods) {
// This is a Sync server
gpr_log(GPR_INFO,
"Synchronous server. Num CQs: %d, Min pollers: %d, Max Pollers: "
"%d, CQ timeout (msec): %d",
sync_server_settings_.num_cqs, sync_server_settings_.min_pollers,
sync_server_settings_.max_pollers,
sync_server_settings_.cq_timeout_msec);
LOG(INFO) << "Synchronous server. Num CQs: "
<< sync_server_settings_.num_cqs
<< ", Min pollers: " << sync_server_settings_.min_pollers
<< ", Max Pollers: " << sync_server_settings_.max_pollers
<< ", CQ timeout (msec): "
<< sync_server_settings_.cq_timeout_msec;
}
if (has_callback_methods) {
@ -451,8 +449,8 @@ std::unique_ptr<grpc::Server> ServerBuilder::BuildAndStart() {
auto success = grpc_server_add_passive_listener(
core_server, creds, std::move(passive_listener));
if (!success.ok()) {
gpr_log(GPR_ERROR, "Failed to create a passive listener: %s",
success.ToString().c_str());
LOG(ERROR) << "Failed to create a passive listener: "
<< success.ToString();
return nullptr;
}
}
@ -483,9 +481,8 @@ std::unique_ptr<grpc::Server> ServerBuilder::BuildAndStart() {
} else {
for (const auto& value : services_) {
if (value->service->has_generic_methods()) {
gpr_log(GPR_ERROR,
"Some methods were marked generic but there is no "
"generic service registered.");
LOG(ERROR) << "Some methods were marked generic but there is no "
"generic service registered.";
return nullptr;
}
}
@ -525,7 +522,7 @@ ServerBuilder& ServerBuilder::EnableWorkaround(grpc_workaround_list id) {
case GRPC_WORKAROUND_ID_CRONET_COMPRESSION:
return AddChannelArgument(GRPC_ARG_WORKAROUND_CRONET_COMPRESSION, 1);
default:
gpr_log(GPR_ERROR, "Workaround %u does not exist or is obsolete.", id);
LOG(ERROR) << "Workaround " << id << " does not exist or is obsolete.";
return *this;
}
}

@ -1058,8 +1058,7 @@ bool Server::RegisterService(const std::string* addr, grpc::Service* service) {
server_, method->name(), addr ? addr->c_str() : nullptr,
PayloadHandlingForMethod(method.get()), 0);
if (method_registration_tag == nullptr) {
gpr_log(GPR_DEBUG, "Attempt to register %s multiple times",
method->name());
VLOG(2) << "Attempt to register " << method->name() << " multiple times";
return false;
}

Loading…
Cancel
Save