Avoid low severity log message construction

pull/14945/head
Ara Ayvazyan 7 years ago
parent 586704b980
commit e7995f213c
  1. 2
      include/grpc/support/log.h
  2. 10
      src/core/lib/gpr/log.cc
  3. 4
      src/core/lib/gpr/log_android.cc
  4. 4
      src/core/lib/gpr/log_linux.cc
  5. 4
      src/core/lib/gpr/log_posix.cc
  6. 5
      src/core/lib/gpr/log_windows.cc

@ -61,6 +61,8 @@ GPRAPI const char* gpr_log_severity_string(gpr_log_severity severity);
GPRAPI void gpr_log(const char* file, int line, gpr_log_severity severity,
const char* format, ...) GPR_PRINT_FORMAT_CHECK(4, 5);
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);

@ -44,10 +44,16 @@ const char* gpr_log_severity_string(gpr_log_severity severity) {
GPR_UNREACHABLE_CODE(return "UNKNOWN");
}
int gpr_should_log(gpr_log_severity severity) {
return static_cast<gpr_atm>(severity) >=
gpr_atm_no_barrier_load(&g_min_severity_to_print)
? 1
: 0;
}
void gpr_log_message(const char* file, int line, gpr_log_severity severity,
const char* message) {
if (static_cast<gpr_atm>(severity) <
gpr_atm_no_barrier_load(&g_min_severity_to_print)) {
if (gpr_should_log(severity) == 0) {
return;
}

@ -41,6 +41,10 @@ static android_LogPriority severity_to_log_priority(gpr_log_severity severity) {
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 */
if (gpr_should_log(severity) == 0) {
return;
}
char* message = NULL;
va_list args;
va_start(args, format);

@ -44,6 +44,10 @@ static long gettid(void) { return syscall(__NR_gettid); }
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 */
if (gpr_should_log(severity) == 0) {
return;
}
char* message = nullptr;
va_list args;
va_start(args, format);

@ -34,6 +34,10 @@ static intptr_t gettid(void) { return (intptr_t)pthread_self(); }
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 */
if (gpr_should_log(severity) == 0) {
return;
}
char buf[64];
char* allocated = nullptr;
char* message = nullptr;

@ -34,6 +34,11 @@
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 */
if (gpr_should_log(severity) == 0) {
return;
}
char* message = NULL;
va_list args;
int ret;

Loading…
Cancel
Save