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

pull/36594/head
tanvi-jagtap 11 months ago
parent 69237b6786
commit 969cd32c41
  1. 24
      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), &(call->context), &(call->request), &(call->response),
[this, call](Status status) { [this, call](Status status) {
if (!status.ok()) { if (!status.ok()) {
gpr_log( LOG(ERROR) << "GCP Observability Logging Error "
GPR_ERROR, << status.error_code() << ": " << status.error_message()
"GCP Observability Logging Error %d: %s. Dumping log entries.", << ". Dumping log entries.";
status.error_code(), status.error_message().c_str());
for (auto& entry : call->request.entries()) { for (auto& entry : call->request.entries()) {
std::string output; std::string output;
::google::protobuf::TextFormat::PrintToString(entry.json_payload(), ::google::protobuf::TextFormat::PrintToString(entry.json_payload(),
&output); &output);
gpr_log( LOG(INFO) << "Log Entry recorded at time: "
GPR_INFO, "Log Entry recorded at time: %s : %s", << grpc_core::Timestamp::FromTimespecRoundUp(
grpc_core::Timestamp::FromTimespecRoundUp(
gpr_timespec{entry.timestamp().seconds(), gpr_timespec{entry.timestamp().seconds(),
entry.timestamp().nanos(), GPR_CLOCK_REALTIME}) entry.timestamp().nanos(),
GPR_CLOCK_REALTIME})
.ToString() .ToString()
.c_str(), << " : " << output;
output.c_str());
} }
} }
delete call; delete call;
@ -414,7 +412,7 @@ void ObservabilityLoggingSink::MaybeTriggerFlushLocked() {
if (entries_.empty()) return; if (entries_.empty()) return;
if (entries_.size() > kMaxEntriesBeforeDump || if (entries_.size() > kMaxEntriesBeforeDump ||
entries_memory_footprint_ > kMaxMemoryFootprintBeforeDump) { 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."; LOG(INFO) << "Buffer limit reached. Dumping log entries.";
for (auto& entry : entries_) { for (auto& entry : entries_) {
google::protobuf::Struct proto; google::protobuf::Struct proto;
@ -422,8 +420,8 @@ void ObservabilityLoggingSink::MaybeTriggerFlushLocked() {
EntryToJsonStructProto(std::move(entry), &proto); EntryToJsonStructProto(std::move(entry), &proto);
std::string output; std::string output;
::google::protobuf::TextFormat::PrintToString(proto, &output); ::google::protobuf::TextFormat::PrintToString(proto, &output);
gpr_log(GPR_INFO, "Log Entry recorded at time: %s : %s", LOG(INFO) << "Log Entry recorded at time: " << timestamp << " : "
timestamp.c_str(), output.c_str()); << output;
} }
entries_.clear(); entries_.clear();
entries_memory_footprint_ = 0; entries_memory_footprint_ = 0;

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

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

Loading…
Cancel
Save