[Gpr_To_Absl_Logging] Remove gpr_log. Adding absl LOG wrappers. (#37431)
[Gpr_To_Absl_Logging] Remove gpr_log. Adding absl LOG wrappers
List of changes in this PR
1. Replacing all instances of gpr_log in PHP and RUBY with the new absl wrapper APIs. The replacement mapping is given below
gpr_log(GPR_ERROR, ...)
=> grpc_absl_log_error
gpr_log(GPR_INFO, ...)
=> grpc_absl_log_info - Printing a simple message
=> grpc_absl_log_info_int - Printing a message and a number
=> grpc_absl_log_info_str - Printing 2 strings.
gpr_log(GPR_DEBUG, ...)
=> grpc_absl_vlog - Printing a simple message
=> grpc_absl_vlog_int - Printing a message and a number
=> grpc_absl_vlog_str - Printing 2 strings.
Adding grpc_absl_vlog2_enabled() check around gpr_log(GPR_DEBUG, ...)
2. src/python/grpcio_observability/grpc_observability/observability_util.cc One instance of gpr_log to absl LOG replacement was missed earlier. Fixing that.
3. Deleting deprecated gpr stuff : gpr_log_severity , GPR_DEBUG , GPR_INFO , GPR_ERROR , gpr_log .
4. Adding new APIs for Ruby and PHP. These APIs are very simple wrappers around absl.
5. Removing the legacy functions in platform specific log.cc files. These files are safe to delete now.
6. Fixing the allow list in banned_functions.py . This makes sure that these new wrappers don't get used all over the place by everyone. We carefully only allow list the PHP and RUBY files and allow the use of these wrappers. Everywhere else - using these wrappers should fail Sanity Tests.
Closes #37431
COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/37431 from tanvi-jagtap:remove_gpr_error 6e5e9bcfcc
PiperOrigin-RevId: 668586873
pull/37597/head
parent
2d99ca4e0b
commit
245941e0da
32 changed files with 192 additions and 476 deletions
@ -1,52 +0,0 @@ |
||||
//
|
||||
//
|
||||
// Copyright 2015 gRPC authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
//
|
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#ifdef GPR_ANDROID |
||||
|
||||
#include <android/log.h> |
||||
#include <stdarg.h> |
||||
#include <stdio.h> |
||||
#include <string.h> |
||||
|
||||
#include <grpc/support/log.h> |
||||
#include <grpc/support/time.h> |
||||
|
||||
#include "src/core/lib/gprpp/crash.h" |
||||
|
||||
extern int gpr_should_log(gpr_log_severity severity); |
||||
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
|
||||
if (gpr_should_log(severity) == 0) { |
||||
return; |
||||
} |
||||
char* message = NULL; |
||||
va_list args; |
||||
va_start(args, format); |
||||
vasprintf(&message, format, args); |
||||
va_end(args); |
||||
gpr_log_message(file, line, severity, message); |
||||
free(message); |
||||
} |
||||
|
||||
#endif // GPR_ANDROID
|
@ -1,73 +0,0 @@ |
||||
//
|
||||
//
|
||||
// Copyright 2015 gRPC authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
//
|
||||
|
||||
#ifndef _POSIX_SOURCE |
||||
#define _POSIX_SOURCE |
||||
#endif |
||||
|
||||
#ifndef _GNU_SOURCE |
||||
#define _GNU_SOURCE |
||||
#endif |
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#ifdef GPR_LINUX_LOG |
||||
|
||||
#include <inttypes.h> |
||||
#include <stdarg.h> |
||||
#include <stdio.h> |
||||
#include <string.h> |
||||
#include <sys/syscall.h> |
||||
#include <time.h> |
||||
#include <unistd.h> |
||||
|
||||
#include <string> |
||||
|
||||
#include "absl/strings/str_format.h" |
||||
|
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/log.h> |
||||
#include <grpc/support/time.h> |
||||
|
||||
#include "src/core/lib/gprpp/crash.h" |
||||
#include "src/core/lib/gprpp/examine_stack.h" |
||||
|
||||
extern int gpr_should_log(gpr_log_severity severity); |
||||
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
|
||||
if (gpr_should_log(severity) == 0) { |
||||
return; |
||||
} |
||||
char* message = nullptr; |
||||
va_list args; |
||||
va_start(args, format); |
||||
if (vasprintf(&message, format, args) == -1) { |
||||
va_end(args); |
||||
return; |
||||
} |
||||
va_end(args); |
||||
gpr_log_message(file, line, severity, message); |
||||
// message has been allocated by vasprintf above, and needs free
|
||||
free(message); |
||||
} |
||||
|
||||
#endif // GPR_LINUX_LOG
|
@ -1,73 +0,0 @@ |
||||
//
|
||||
//
|
||||
// Copyright 2015 gRPC authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
//
|
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#ifdef GPR_POSIX_LOG |
||||
|
||||
#include <inttypes.h> |
||||
#include <pthread.h> |
||||
#include <stdarg.h> |
||||
#include <stdio.h> |
||||
#include <string.h> |
||||
#include <time.h> |
||||
|
||||
#include <string> |
||||
|
||||
#include "absl/strings/str_format.h" |
||||
|
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/log.h> |
||||
#include <grpc/support/time.h> |
||||
|
||||
#include "src/core/lib/gprpp/crash.h" |
||||
#include "src/core/lib/gprpp/examine_stack.h" |
||||
|
||||
extern int gpr_should_log(gpr_log_severity severity); |
||||
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
|
||||
if (gpr_should_log(severity) == 0) { |
||||
return; |
||||
} |
||||
char buf[64]; |
||||
char* allocated = nullptr; |
||||
char* message = nullptr; |
||||
int ret; |
||||
va_list args; |
||||
va_start(args, format); |
||||
ret = vsnprintf(buf, sizeof(buf), format, args); |
||||
va_end(args); |
||||
if (ret < 0) { |
||||
message = nullptr; |
||||
} else if ((size_t)ret <= sizeof(buf) - 1) { |
||||
message = buf; |
||||
} else { |
||||
message = allocated = (char*)gpr_malloc((size_t)ret + 1); |
||||
va_start(args, format); |
||||
vsnprintf(message, (size_t)(ret + 1), format, args); |
||||
va_end(args); |
||||
} |
||||
gpr_log_message(file, line, severity, message); |
||||
gpr_free(allocated); |
||||
} |
||||
|
||||
#endif // defined(GPR_POSIX_LOG)
|
@ -1,77 +0,0 @@ |
||||
//
|
||||
//
|
||||
// Copyright 2015 gRPC authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
//
|
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#ifdef GPR_WINDOWS_LOG |
||||
|
||||
#include <stdarg.h> |
||||
#include <stdio.h> |
||||
|
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/log.h> |
||||
#include <grpc/support/log_windows.h> |
||||
#include <grpc/support/string_util.h> |
||||
#include <grpc/support/time.h> |
||||
|
||||
#include "src/core/lib/gprpp/crash.h" |
||||
#include "src/core/lib/gprpp/examine_stack.h" |
||||
#include "src/core/util/string.h" |
||||
|
||||
extern int gpr_should_log(gpr_log_severity severity); |
||||
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
|
||||
if (gpr_should_log(severity) == 0) { |
||||
return; |
||||
} |
||||
|
||||
char* message = NULL; |
||||
va_list args; |
||||
int ret; |
||||
|
||||
// Determine the length.
|
||||
va_start(args, format); |
||||
ret = _vscprintf(format, args); |
||||
va_end(args); |
||||
if (ret < 0) { |
||||
message = NULL; |
||||
} else { |
||||
// Allocate a new buffer, with space for the NUL terminator.
|
||||
size_t strp_buflen = (size_t)ret + 1; |
||||
message = (char*)gpr_malloc(strp_buflen); |
||||
|
||||
// Print to the buffer.
|
||||
va_start(args, format); |
||||
ret = vsnprintf_s(message, strp_buflen, _TRUNCATE, format, args); |
||||
va_end(args); |
||||
if ((size_t)ret != strp_buflen - 1) { |
||||
// This should never happen.
|
||||
gpr_free(message); |
||||
message = NULL; |
||||
} |
||||
} |
||||
|
||||
gpr_log_message(file, line, severity, message); |
||||
gpr_free(message); |
||||
} |
||||
|
||||
#endif // GPR_WINDOWS_LOG
|
Loading…
Reference in new issue