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

PiperOrigin-RevId: 633802450
  • Loading branch information
tanvi-jagtap authored and Copybara-Service committed May 15, 2024
1 parent befeeba commit 7eb37d3
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 44 deletions.
3 changes: 2 additions & 1 deletion src/core/lib/security/authorization/evaluate_args.cc
Expand Up @@ -16,6 +16,7 @@

#include <string.h>

#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/match.h"
Expand All @@ -41,7 +42,7 @@ EvaluateArgs::PerChannelArgs::Address ParseEndpointUri(
EvaluateArgs::PerChannelArgs::Address address;
absl::StatusOr<URI> uri = URI::Parse(uri_text);
if (!uri.ok()) {
gpr_log(GPR_DEBUG, "Failed to parse uri.");
VLOG(2) << "Failed to parse uri.";
return address;
}
absl::string_view host_view;
Expand Down
3 changes: 2 additions & 1 deletion src/core/lib/security/context/security_context.cc
Expand Up @@ -23,6 +23,7 @@
#include <algorithm>

#include "absl/log/check.h"
#include "absl/log/log.h"

#include <grpc/credentials.h>
#include <grpc/grpc_security.h>
Expand Down Expand Up @@ -52,7 +53,7 @@ grpc_call_error grpc_call_set_credentials(grpc_call* call,
GRPC_API_TRACE("grpc_call_set_credentials(call=%p, creds=%p)", 2,
(call, creds));
if (!grpc_call_is_client(call)) {
gpr_log(GPR_ERROR, "Method is client-side only.");
LOG(ERROR) << "Method is client-side only.";
return GRPC_CALL_ERROR_NOT_ON_SERVER;
}
ctx = static_cast<grpc_client_security_context*>(
Expand Down
Expand Up @@ -22,6 +22,8 @@
#include <stdio.h>
#include <string.h>

#include "absl/log/log.h"

#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
Expand Down Expand Up @@ -56,7 +58,7 @@ namespace internal {
char* read_bios_file(const char* bios_file) {
FILE* fp = fopen(bios_file, "r");
if (!fp) {
gpr_log(GPR_INFO, "BIOS data file does not exist or cannot be opened.");
LOG(INFO) << "BIOS data file does not exist or cannot be opened.";
return nullptr;
}
char buf[kBiosDataBufferSize + 1];
Expand Down
3 changes: 2 additions & 1 deletion src/core/lib/security/credentials/call_creds_util.cc
Expand Up @@ -18,6 +18,7 @@

#include <string.h>

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

Expand Down Expand Up @@ -47,7 +48,7 @@ ServiceUrlAndMethod MakeServiceUrlAndMethod(
auto last_slash = service.find_last_of('/');
absl::string_view method_name;
if (last_slash == absl::string_view::npos) {
gpr_log(GPR_ERROR, "No '/' found in fully qualified method name");
LOG(ERROR) << "No '/' found in fully qualified method name";
service = "";
method_name = "";
} else if (last_slash == 0) {
Expand Down
Expand Up @@ -24,6 +24,7 @@
#include <string>

#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/status/statusor.h"
#include "absl/strings/match.h"
#include "absl/strings/string_view.h"
Expand Down Expand Up @@ -137,7 +138,7 @@ grpc_google_default_channel_credentials::create_security_connector(
is_xds_non_cfe_cluster;
// Return failure if ALTS is selected but not running on GCE.
if (use_alts && alts_creds_ == nullptr) {
gpr_log(GPR_ERROR, "ALTS is selected, but not running on GCE.");
LOG(ERROR) << "ALTS is selected, but not running on GCE.";
return nullptr;
}
grpc_core::RefCountedPtr<grpc_channel_security_connector> sc =
Expand Down
19 changes: 10 additions & 9 deletions src/core/lib/security/credentials/jwt/json_token.cc
Expand Up @@ -30,6 +30,7 @@
#include <openssl/rsa.h>

#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/escaping.h"
Expand Down Expand Up @@ -86,7 +87,7 @@ grpc_auth_json_key grpc_auth_json_key_create_from_json(const Json& json) {
memset(&result, 0, sizeof(grpc_auth_json_key));
result.type = GRPC_AUTH_JSON_TYPE_INVALID;
if (json.type() == Json::Type::kNull) {
gpr_log(GPR_ERROR, "Invalid json.");
LOG(ERROR) << "Invalid json.";
goto end;
}

Expand Down Expand Up @@ -114,7 +115,7 @@ grpc_auth_json_key grpc_auth_json_key_create_from_json(const Json& json) {
bio = BIO_new(BIO_s_mem());
success = BIO_puts(bio, prop_value);
if ((success < 0) || (static_cast<size_t>(success) != strlen(prop_value))) {
gpr_log(GPR_ERROR, "Could not write into openssl BIO.");
LOG(ERROR) << "Could not write into openssl BIO.";
goto end;
}
#if OPENSSL_VERSION_NUMBER < 0x30000000L
Expand All @@ -124,7 +125,7 @@ grpc_auth_json_key grpc_auth_json_key_create_from_json(const Json& json) {
result.private_key = PEM_read_bio_PrivateKey(bio, nullptr, nullptr, nullptr);
#endif
if (result.private_key == nullptr) {
gpr_log(GPR_ERROR, "Could not deserialize private key.");
LOG(ERROR) << "Could not deserialize private key.";
goto end;
}
success = 1;
Expand Down Expand Up @@ -191,7 +192,7 @@ static char* encoded_jwt_claim(const grpc_auth_json_key* json_key,
gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME);
gpr_timespec expiration = gpr_time_add(now, token_lifetime);
if (gpr_time_cmp(token_lifetime, grpc_max_auth_token_lifetime()) > 0) {
gpr_log(GPR_INFO, "Cropping token lifetime to maximum allowed value.");
LOG(INFO) << "Cropping token lifetime to maximum allowed value.";
expiration = gpr_time_add(now, grpc_max_auth_token_lifetime());
}

Expand Down Expand Up @@ -256,7 +257,7 @@ char* compute_and_encode_signature(const grpc_auth_json_key* json_key,
if (md == nullptr) return nullptr;
md_ctx = EVP_MD_CTX_create();
if (md_ctx == nullptr) {
gpr_log(GPR_ERROR, "Could not create MD_CTX");
LOG(ERROR) << "Could not create MD_CTX";
goto end;
}
#if OPENSSL_VERSION_NUMBER < 0x30000000L
Expand All @@ -266,20 +267,20 @@ char* compute_and_encode_signature(const grpc_auth_json_key* json_key,
if (EVP_DigestSignInit(md_ctx, nullptr, md, nullptr, json_key->private_key) !=
1) {
#endif
gpr_log(GPR_ERROR, "DigestInit failed.");
LOG(ERROR) << "DigestInit failed.";
goto end;
}
if (EVP_DigestSignUpdate(md_ctx, to_sign, strlen(to_sign)) != 1) {
gpr_log(GPR_ERROR, "DigestUpdate failed.");
LOG(ERROR) << "DigestUpdate failed.";
goto end;
}
if (EVP_DigestSignFinal(md_ctx, nullptr, &sig_len) != 1) {
gpr_log(GPR_ERROR, "DigestFinal (get signature length) failed.");
LOG(ERROR) << "DigestFinal (get signature length) failed.";
goto end;
}
sig = static_cast<unsigned char*>(gpr_malloc(sig_len));
if (EVP_DigestSignFinal(md_ctx, sig, &sig_len) != 1) {
gpr_log(GPR_ERROR, "DigestFinal (signature compute) failed.");
LOG(ERROR) << "DigestFinal (signature compute) failed.";
goto end;
}
result =
Expand Down
3 changes: 2 additions & 1 deletion src/core/lib/security/credentials/jwt/jwt_credentials.cc
Expand Up @@ -25,6 +25,7 @@
#include <utility>

#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/strings/str_cat.h"

Expand Down Expand Up @@ -134,7 +135,7 @@ grpc_core::RefCountedPtr<grpc_call_credentials>
grpc_service_account_jwt_access_credentials_create_from_auth_json_key(
grpc_auth_json_key key, gpr_timespec token_lifetime) {
if (!grpc_auth_json_key_is_valid(&key)) {
gpr_log(GPR_ERROR, "Invalid input for jwt credentials creation");
LOG(ERROR) << "Invalid input for jwt credentials creation";
return nullptr;
}
return grpc_core::MakeRefCounted<grpc_service_account_jwt_access_credentials>(
Expand Down
15 changes: 8 additions & 7 deletions src/core/lib/security/credentials/oauth2/oauth2_credentials.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_cat.h"
#include "absl/strings/str_format.h"
Expand Down Expand Up @@ -86,7 +87,7 @@ grpc_auth_refresh_token grpc_auth_refresh_token_create_from_json(
memset(&result, 0, sizeof(grpc_auth_refresh_token));
result.type = GRPC_AUTH_JSON_TYPE_INVALID;
if (json.type() != Json::Type::kObject) {
gpr_log(GPR_ERROR, "Invalid json.");
LOG(ERROR) << "Invalid json.";
goto end;
}

Expand Down Expand Up @@ -161,7 +162,7 @@ grpc_oauth2_token_fetcher_credentials_parse_server_response(
grpc_credentials_status status = GRPC_CREDENTIALS_OK;

if (response == nullptr) {
gpr_log(GPR_ERROR, "Received NULL response.");
LOG(ERROR) << "Received NULL response.";
status = GRPC_CREDENTIALS_ERROR;
goto end;
}
Expand Down Expand Up @@ -193,30 +194,30 @@ grpc_oauth2_token_fetcher_credentials_parse_server_response(
goto end;
}
if (json->type() != Json::Type::kObject) {
gpr_log(GPR_ERROR, "Response should be a JSON object");
LOG(ERROR) << "Response should be a JSON object";
status = GRPC_CREDENTIALS_ERROR;
goto end;
}
it = json->object().find("access_token");
if (it == json->object().end() ||
it->second.type() != Json::Type::kString) {
gpr_log(GPR_ERROR, "Missing or invalid access_token in JSON.");
LOG(ERROR) << "Missing or invalid access_token in JSON.";
status = GRPC_CREDENTIALS_ERROR;
goto end;
}
access_token = it->second.string().c_str();
it = json->object().find("token_type");
if (it == json->object().end() ||
it->second.type() != Json::Type::kString) {
gpr_log(GPR_ERROR, "Missing or invalid token_type in JSON.");
LOG(ERROR) << "Missing or invalid token_type in JSON.";
status = GRPC_CREDENTIALS_ERROR;
goto end;
}
token_type = it->second.string().c_str();
it = json->object().find("expires_in");
if (it == json->object().end() ||
it->second.type() != Json::Type::kNumber) {
gpr_log(GPR_ERROR, "Missing or invalid expires_in in JSON.");
LOG(ERROR) << "Missing or invalid expires_in in JSON.";
status = GRPC_CREDENTIALS_ERROR;
goto end;
}
Expand Down Expand Up @@ -479,7 +480,7 @@ grpc_core::RefCountedPtr<grpc_call_credentials>
grpc_refresh_token_credentials_create_from_auth_refresh_token(
grpc_auth_refresh_token refresh_token) {
if (!grpc_auth_refresh_token_is_valid(&refresh_token)) {
gpr_log(GPR_ERROR, "Invalid input for refresh token credentials creation");
LOG(ERROR) << "Invalid input for refresh token credentials creation";
return nullptr;
}
return grpc_core::MakeRefCounted<grpc_google_refresh_token_credentials>(
Expand Down
Expand Up @@ -22,6 +22,7 @@
#include <memory>

#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
Expand Down Expand Up @@ -83,7 +84,7 @@ grpc_plugin_credentials::PendingRequest::ProcessPluginResult(
!GRPC_LOG_IF_ERROR(
"validate_metadata_from_plugin",
grpc_validate_header_nonbin_value_is_legal(md[i].value))) {
gpr_log(GPR_ERROR, "Plugin added invalid metadata value.");
LOG(ERROR) << "Plugin added invalid metadata value.";
seen_illegal_header = true;
break;
}
Expand Down
9 changes: 5 additions & 4 deletions src/core/lib/security/credentials/ssl/ssl_credentials.cc
Expand Up @@ -24,6 +24,7 @@
#include <utility>

#include "absl/log/check.h"
#include "absl/log/log.h"
#include "absl/types/optional.h"

#include <grpc/impl/channel_arg_names.h>
Expand Down Expand Up @@ -54,7 +55,7 @@ grpc_ssl_credentials::grpc_ssl_credentials(
const char* pem_root_certs =
grpc_core::DefaultSslRootStore::GetPemRootCerts();
if (pem_root_certs == nullptr) {
gpr_log(GPR_ERROR, "Could not get default pem root certs.");
LOG(ERROR) << "Could not get default pem root certs.";
} else {
char* default_roots = gpr_strdup(pem_root_certs);
config_.pem_root_certs = default_roots;
Expand Down Expand Up @@ -378,7 +379,7 @@ grpc_ssl_server_credentials_create_options_using_config(
grpc_ssl_server_certificate_config* config) {
grpc_ssl_server_credentials_options* options = nullptr;
if (config == nullptr) {
gpr_log(GPR_ERROR, "Certificate config must not be NULL.");
LOG(ERROR) << "Certificate config must not be NULL.";
goto done;
}
options = static_cast<grpc_ssl_server_credentials_options*>(
Expand All @@ -394,7 +395,7 @@ grpc_ssl_server_credentials_create_options_using_config_fetcher(
grpc_ssl_client_certificate_request_type client_certificate_request,
grpc_ssl_server_certificate_config_callback cb, void* user_data) {
if (cb == nullptr) {
gpr_log(GPR_ERROR, "Invalid certificate config callback parameter.");
LOG(ERROR) << "Invalid certificate config callback parameter.";
return nullptr;
}

Expand Down Expand Up @@ -466,7 +467,7 @@ grpc_server_credentials* grpc_ssl_server_credentials_create_with_options(
goto done;
} else if (options->certificate_config_fetcher != nullptr &&
options->certificate_config_fetcher->cb == nullptr) {
gpr_log(GPR_ERROR, "Certificate config fetcher callback must not be NULL.");
LOG(ERROR) << "Certificate config fetcher callback must not be NULL.";
goto done;
}

Expand Down
Expand Up @@ -21,6 +21,7 @@
#include <memory>

#include "absl/log/check.h"
#include "absl/log/log.h"

#include <grpc/grpc_crl_provider.h>
#include <grpc/support/log.h>
Expand Down Expand Up @@ -131,7 +132,7 @@ void grpc_tls_credentials_options_set_tls_session_key_log_file_path(
gpr_log(GPR_INFO,
"Enabling TLS session key logging with keys stored at: %s", path);
} else {
gpr_log(GPR_INFO, "Disabling TLS session key logging");
LOG(INFO) << "Disabling TLS session key logging";
}
options->set_tls_session_key_log_file_path(path != nullptr ? path : "");
}
Expand Down
9 changes: 5 additions & 4 deletions src/core/lib/security/credentials/tls/tls_credentials.cc
Expand Up @@ -22,6 +22,7 @@
#include <string>
#include <utility>

#include "absl/log/log.h"
#include "absl/types/optional.h"

#include <grpc/grpc.h>
Expand All @@ -42,22 +43,22 @@ namespace {
bool CredentialOptionSanityCheck(grpc_tls_credentials_options* options,
bool is_client) {
if (options == nullptr) {
gpr_log(GPR_ERROR, "TLS credentials options is nullptr.");
LOG(ERROR) << "TLS credentials options is nullptr.";
return false;
}
// In this case, there will be non-retriable handshake errors.
if (options->min_tls_version() > options->max_tls_version()) {
gpr_log(GPR_ERROR, "TLS min version must not be higher than max version.");
LOG(ERROR) << "TLS min version must not be higher than max version.";
grpc_tls_credentials_options_destroy(options);
return false;
}
if (options->max_tls_version() > grpc_tls_version::TLS1_3) {
gpr_log(GPR_ERROR, "TLS max version must not be higher than v1.3.");
LOG(ERROR) << "TLS max version must not be higher than v1.3.";
grpc_tls_credentials_options_destroy(options);
return false;
}
if (options->min_tls_version() < grpc_tls_version::TLS1_2) {
gpr_log(GPR_ERROR, "TLS min version must not be lower than v1.2.");
LOG(ERROR) << "TLS min version must not be lower than v1.2.";
grpc_tls_credentials_options_destroy(options);
return false;
}
Expand Down
Expand Up @@ -32,6 +32,8 @@
#include <sys/stat.h>
#include <unistd.h>

#include "absl/log/log.h"

#include <grpc/support/alloc.h>
#include <grpc/support/log.h>

Expand Down Expand Up @@ -110,7 +112,7 @@ grpc_slice CreateRootCertsBundle(const char* certs_directory) {
if (stat_return == -1 || !S_ISREG(dir_entry_stat.st_mode)) {
// no subdirectories.
if (stat_return == -1) {
gpr_log(GPR_ERROR, "failed to get status for file: %s", file_data.path);
LOG(ERROR) << "failed to get status for file: " << file_data.path;
}
continue;
}
Expand All @@ -131,7 +133,7 @@ grpc_slice CreateRootCertsBundle(const char* certs_directory) {
if (read_ret != -1) {
bytes_read += read_ret;
} else {
gpr_log(GPR_ERROR, "failed to read file: %s", roots_filenames[i].path);
LOG(ERROR) << "failed to read file: " << roots_filenames[i].path;
}
}
}
Expand Down

0 comments on commit 7eb37d3

Please sign in to comment.