[Gpr_To_Absl_Logging] Code clean up (#37270)

Closes #37270

COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/37270 from tanvi-jagtap:gpr_log_for_ruby 1628fa8ebb
PiperOrigin-RevId: 655124415
pull/37296/head^2
Tanvi Jagtap 4 months ago committed by Copybara-Service
parent 729847ab76
commit 8d4bc567e9
  1. 1
      grpc.def
  2. 3
      include/grpc/support/log.h
  3. 3
      src/core/util/android/log.cc
  4. 3
      src/core/util/linux/log.cc
  5. 37
      src/core/util/log.cc
  6. 3
      src/core/util/posix/log.cc
  7. 3
      src/core/util/windows/log.cc
  8. 2
      src/ruby/ext/grpc/rb_grpc_imports.generated.c
  9. 3
      src/ruby/ext/grpc/rb_grpc_imports.generated.h

1
grpc.def generated

@ -232,7 +232,6 @@ EXPORTS
gpr_cpu_current_cpu
gpr_log
gpr_should_log
gpr_log_message
gpr_set_log_verbosity
gpr_log_verbosity_init
gpr_set_log_function

@ -53,9 +53,6 @@ GPRAPI void gpr_log(const char* file, int line, gpr_log_severity severity,
GPRAPI int gpr_should_log(gpr_log_severity severity);
GPRAPI void gpr_log_message(const char* file, int line,
gpr_log_severity severity, const char* message);
/** Set global log verbosity */
GPRAPI void gpr_set_log_verbosity(gpr_log_severity deprecated_setting);

@ -30,6 +30,9 @@
#include "src/core/lib/gprpp/crash.h"
extern void gpr_log_message(const char* file, int line,
gpr_log_severity severity, const char* message);
void gpr_log(const char* file, int line, gpr_log_severity severity,
const char* format, ...) {
// Avoid message construction if gpr_log_message won't log

@ -47,6 +47,9 @@
#include "src/core/lib/gprpp/crash.h"
#include "src/core/lib/gprpp/examine_stack.h"
extern void gpr_log_message(const char* file, int line,
gpr_log_severity severity, const char* message);
void gpr_log(const char* file, int line, gpr_log_severity severity,
const char* format, ...) {
// Avoid message construction if gpr_log_message won't log

@ -35,10 +35,6 @@
#include "src/core/lib/gprpp/crash.h"
#include "src/core/util/string.h"
void gpr_default_log(gpr_log_func_args* args);
void gpr_platform_log(gpr_log_func_args* args);
static gpr_atm g_log_func = reinterpret_cast<gpr_atm>(gpr_default_log);
void gpr_unreachable_code(const char* reason, const char* file, int line) {
grpc_core::Crash(absl::StrCat("UNREACHABLE CODE: ", reason),
grpc_core::SourceLocation(file, line));
@ -63,40 +59,29 @@ int gpr_should_log(gpr_log_severity severity) {
}
}
void gpr_default_log(gpr_log_func_args* args) {
switch (args->severity) {
void gpr_log_message(const char* file, int line, gpr_log_severity severity,
const char* message) {
if (gpr_should_log(severity) == 0) {
return;
}
switch (severity) {
case GPR_LOG_SEVERITY_DEBUG:
// Log DEBUG messages as VLOG(2).
VLOG(2).AtLocation(args->file, args->line) << args->message;
VLOG(2).AtLocation(file, line) << message;
return;
case GPR_LOG_SEVERITY_INFO:
LOG(INFO).AtLocation(args->file, args->line) << args->message;
LOG(INFO).AtLocation(file, line) << message;
return;
case GPR_LOG_SEVERITY_ERROR:
LOG(ERROR).AtLocation(args->file, args->line) << args->message;
LOG(ERROR).AtLocation(file, line) << message;
return;
default:
LOG(ERROR) << __func__ << ": unknown gpr log severity(" << args->severity
LOG(ERROR) << __func__ << ": unknown gpr log severity(" << severity
<< "), using ERROR";
LOG(ERROR).AtLocation(args->file, args->line) << args->message;
LOG(ERROR).AtLocation(file, line) << message;
}
}
void gpr_log_message(const char* file, int line, gpr_log_severity severity,
const char* message) {
if (gpr_should_log(severity) == 0) {
return;
}
gpr_log_func_args lfargs;
memset(&lfargs, 0, sizeof(lfargs));
lfargs.file = file;
lfargs.line = line;
lfargs.severity = severity;
lfargs.message = message;
reinterpret_cast<gpr_log_func>(gpr_atm_no_barrier_load(&g_log_func))(&lfargs);
}
void gpr_set_log_verbosity(
[[maybe_unused]] gpr_log_severity deprecated_setting) {
LOG(ERROR)

@ -38,6 +38,9 @@
#include "src/core/lib/gprpp/crash.h"
#include "src/core/lib/gprpp/examine_stack.h"
extern void gpr_log_message(const char* file, int line,
gpr_log_severity severity, const char* message);
void gpr_log(const char* file, int line, gpr_log_severity severity,
const char* format, ...) {
// Avoid message construction if gpr_log_message won't log

@ -33,6 +33,9 @@
#include "src/core/lib/gprpp/examine_stack.h"
#include "src/core/util/string.h"
extern void gpr_log_message(const char* file, int line,
gpr_log_severity severity, const char* message);
void gpr_log(const char* file, int line, gpr_log_severity severity,
const char* format, ...) {
// Avoid message construction if gpr_log_message won't log

@ -255,7 +255,6 @@ gpr_cpu_num_cores_type gpr_cpu_num_cores_import;
gpr_cpu_current_cpu_type gpr_cpu_current_cpu_import;
gpr_log_type gpr_log_import;
gpr_should_log_type gpr_should_log_import;
gpr_log_message_type gpr_log_message_import;
gpr_set_log_verbosity_type gpr_set_log_verbosity_import;
gpr_log_verbosity_init_type gpr_log_verbosity_init_import;
gpr_set_log_function_type gpr_set_log_function_import;
@ -543,7 +542,6 @@ void grpc_rb_load_imports(HMODULE library) {
gpr_cpu_current_cpu_import = (gpr_cpu_current_cpu_type) GetProcAddress(library, "gpr_cpu_current_cpu");
gpr_log_import = (gpr_log_type) GetProcAddress(library, "gpr_log");
gpr_should_log_import = (gpr_should_log_type) GetProcAddress(library, "gpr_should_log");
gpr_log_message_import = (gpr_log_message_type) GetProcAddress(library, "gpr_log_message");
gpr_set_log_verbosity_import = (gpr_set_log_verbosity_type) GetProcAddress(library, "gpr_set_log_verbosity");
gpr_log_verbosity_init_import = (gpr_log_verbosity_init_type) GetProcAddress(library, "gpr_log_verbosity_init");
gpr_set_log_function_import = (gpr_set_log_function_type) GetProcAddress(library, "gpr_set_log_function");

@ -741,9 +741,6 @@ extern gpr_log_type gpr_log_import;
typedef int(*gpr_should_log_type)(gpr_log_severity severity);
extern gpr_should_log_type gpr_should_log_import;
#define gpr_should_log gpr_should_log_import
typedef void(*gpr_log_message_type)(const char* file, int line, gpr_log_severity severity, const char* message);
extern gpr_log_message_type gpr_log_message_import;
#define gpr_log_message gpr_log_message_import
typedef void(*gpr_set_log_verbosity_type)(gpr_log_severity deprecated_setting);
extern gpr_set_log_verbosity_type gpr_set_log_verbosity_import;
#define gpr_set_log_verbosity gpr_set_log_verbosity_import

Loading…
Cancel
Save