diff --git a/Makefile b/Makefile index 03de0aaae292c7882869149c003691f1c6dd7ed3..80a2e5142fe7a3c33e9d19553d5f29175486b1de 100644 --- a/Makefile +++ b/Makefile @@ -674,7 +674,7 @@ LIBGRPC_SRC = \ src/core/statistics/census_rpc_stats.c \ src/core/statistics/census_tracing.c \ src/core/statistics/hash_table.c \ - src/core/statistics/log.c \ + src/core/statistics/census_log.c \ src/core/statistics/window_stats.c \ src/core/surface/byte_buffer.c \ src/core/surface/byte_buffer_reader.c \ @@ -1592,7 +1592,7 @@ LIBGRPC_UNSECURE_SRC = \ src/core/statistics/census_rpc_stats.c \ src/core/statistics/census_tracing.c \ src/core/statistics/hash_table.c \ - src/core/statistics/log.c \ + src/core/statistics/census_log.c \ src/core/statistics/window_stats.c \ src/core/surface/byte_buffer.c \ src/core/surface/byte_buffer_reader.c \ diff --git a/build.json b/build.json index e6158262ff0e4b669e445360ead7ba6f98ec2907..b4dc9b66bf0bfc467bf916b4f0829213e6cb40fb 100644 --- a/build.json +++ b/build.json @@ -137,7 +137,7 @@ "src/core/statistics/census_rpc_stats.c", "src/core/statistics/census_tracing.c", "src/core/statistics/hash_table.c", - "src/core/statistics/log.c", + "src/core/statistics/census_log.c", "src/core/statistics/window_stats.c", "src/core/surface/byte_buffer.c", "src/core/surface/byte_buffer_reader.c", @@ -228,7 +228,7 @@ "src/core/statistics/census_interface.h", "src/core/statistics/census_rpc_stats.h", "src/core/statistics/hash_table.h", - "src/core/statistics/log.h", + "src/core/statistics/census_log.h", "src/core/statistics/window_stats.h", "src/core/surface/call.h", "src/core/surface/channel.h", diff --git a/include/grpc/support/log.h b/include/grpc/support/log.h index b79d661f65ad905a7052bd3f137d52fd299a76fa..5d0b790867376f1f3337c3a3aa0c8b7195078c0d 100644 --- a/include/grpc/support/log.h +++ b/include/grpc/support/log.h @@ -35,6 +35,7 @@ #define __GRPC_SUPPORT_LOG_H__ #include <stdlib.h> /* for abort() */ +#include <stdarg.h> #ifdef __cplusplus extern "C" { @@ -71,6 +72,10 @@ const char *gpr_log_severity_string(gpr_log_severity severity); void gpr_log(const char *file, int line, gpr_log_severity severity, const char *format, ...); +/* Same as above, but using a va_list instead. */ +void gpr_vlog(const char *file, int line, gpr_log_severity severity, + const char *format, va_list args); + /* abort() the process if x is zero, having written a line to the log. Intended for internal invariants. If the error can be recovered from, diff --git a/src/core/channel/connected_channel.c b/src/core/channel/connected_channel.c index 5dc4d7a5d411fab4dafa534ddf8e1b26cde0faec..8581fb41d61638995edb6c16e85929e632f77904 100644 --- a/src/core/channel/connected_channel.c +++ b/src/core/channel/connected_channel.c @@ -289,15 +289,12 @@ static void accept_stream(void *user_data, grpc_transport *transport, static void recv_error(channel_data *chand, call_data *calld, int line, const char *fmt, ...) { - char msg[512]; va_list a; va_start(a, fmt); - vsprintf(msg, fmt, a); + gpr_vlog(__FILE__, line, GPR_LOG_SEVERITY_ERROR, fmt, a); va_end(a); - gpr_log(__FILE__, line, GPR_LOG_SEVERITY_ERROR, "%s", msg); - if (chand->transport) { grpc_transport_abort_stream(chand->transport, TRANSPORT_STREAM_FROM_CALL_DATA(calld), diff --git a/src/core/statistics/log.c b/src/core/statistics/census_log.c similarity index 99% rename from src/core/statistics/log.c rename to src/core/statistics/census_log.c index 43a8653de66ca8ea8b1b158b1adf5c09a3cd3724..9de9d2efb720293d240718d25d7d80c9a0d29103 100644 --- a/src/core/statistics/log.c +++ b/src/core/statistics/census_log.c @@ -89,7 +89,7 @@ include the name of the structure, which will be passed as the first argument. E.g. cl_block_initialize() will initialize a cl_block. */ -#include "src/core/statistics/log.h" +#include "src/core/statistics/census_log.h" #include <string.h> #include "src/core/support/cpu.h" #include <grpc/support/alloc.h> diff --git a/src/core/statistics/log.h b/src/core/statistics/census_log.h similarity index 100% rename from src/core/statistics/log.h rename to src/core/statistics/census_log.h diff --git a/src/core/support/log.c b/src/core/support/log.c index 79321f7ffe7a5859b25c8273297d3167a4de7ce7..b9e2897efc341777a2277f598d3898a4c0193d60 100644 --- a/src/core/support/log.c +++ b/src/core/support/log.c @@ -46,3 +46,13 @@ const char *gpr_log_severity_string(gpr_log_severity severity) { } return "UNKNOWN"; } + +void gpr_log(const char *file, int line, gpr_log_severity severity, + const char *format, ...) { + va_list args; + va_start(args, format); + + gpr_vlog(file, line, severity, format, args); + + va_end(args); +} diff --git a/src/core/support/log_android.c b/src/core/support/log_android.c index 9e2b03471f5b54f9d7ee23ee95a3dd357546a780..4c83e09914625a4f46eef60b4f082f504a9add70 100644 --- a/src/core/support/log_android.c +++ b/src/core/support/log_android.c @@ -54,15 +54,13 @@ static android_LogPriority severity_to_log_priority(gpr_log_severity severity) { return ANDROID_LOG_DEFAULT; } -void gpr_log(const char *file, int line, gpr_log_severity severity, - const char *format, ...) { +void gpr_vlog(const char *file, int line, gpr_log_severity severity, + const char *format, va_list args) { char *final_slash; const char *display_file; char *prefix = NULL; char *suffix = NULL; char *output = NULL; - va_list args; - va_start(args, format); final_slash = strrchr(file, '/'); if (final_slash == NULL) @@ -73,7 +71,6 @@ void gpr_log(const char *file, int line, gpr_log_severity severity, asprintf(&prefix, "%s:%d] ", display_file, line); vasprintf(&suffix, format, args); asprintf(&output, "%s%s", prefix, suffix); - va_end(args); __android_log_write(severity_to_log_priority(severity), "GRPC", output); diff --git a/src/core/support/log_linux.c b/src/core/support/log_linux.c index e39e2cc166dd4f02c8e2bb965e237123f3219c86..322ff07dd90db33c807a208519283c492f2ed152 100644 --- a/src/core/support/log_linux.c +++ b/src/core/support/log_linux.c @@ -49,15 +49,13 @@ static long gettid() { return syscall(__NR_gettid); } -void gpr_log(const char *file, int line, gpr_log_severity severity, - const char *format, ...) { +void gpr_vlog(const char *file, int line, gpr_log_severity severity, + const char *format, va_list args) { char *final_slash; const char *display_file; char time_buffer[64]; gpr_timespec now = gpr_now(); struct tm tm; - va_list args; - va_start(args, format); final_slash = strrchr(file, '/'); if (final_slash == NULL) @@ -78,8 +76,6 @@ void gpr_log(const char *file, int line, gpr_log_severity severity, vfprintf(stderr, format, args); fputc('\n', stderr); funlockfile(stderr); - - va_end(args); } #endif diff --git a/src/core/support/log_posix.c b/src/core/support/log_posix.c index 68882f7e89f6dabd077dffd17dcb3bb02c9fe0f8..b47c433cd717906b32d0920c2f50484aa35a1c3b 100644 --- a/src/core/support/log_posix.c +++ b/src/core/support/log_posix.c @@ -47,15 +47,13 @@ static long gettid() { return pthread_self(); } -void gpr_log(const char *file, int line, gpr_log_severity severity, - const char *format, ...) { +void gpr_vlog(const char *file, int line, gpr_log_severity severity, + const char *format, va_list args) { char *final_slash; const char *display_file; char time_buffer[64]; gpr_timespec now = gpr_now(); struct tm tm; - va_list args; - va_start(args, format); final_slash = strrchr(file, '/'); if (final_slash == NULL) @@ -76,8 +74,6 @@ void gpr_log(const char *file, int line, gpr_log_severity severity, vfprintf(stderr, format, args); fputc('\n', stderr); funlockfile(stderr); - - va_end(args); } #endif /* defined(GPR_POSIX_LOG) */ diff --git a/src/core/support/log_win32.c b/src/core/support/log_win32.c index fb2fc0c239598c872f90915edba488be70369dde..e6567dca7e7e5f8fa9bbc04bb0ea4405e1683fbb 100644 --- a/src/core/support/log_win32.c +++ b/src/core/support/log_win32.c @@ -40,16 +40,11 @@ #include <stdarg.h> /* Simple starter implementation */ -void gpr_log(const char *file, int line, gpr_log_severity severity, - const char *format, ...) { - va_list args; - va_start(args, format); - +void gpr_vlog(const char *file, int line, gpr_log_severity severity, + const char *format, va_list args) { fprintf(stderr, "%s %s:%d: ", gpr_log_severity_string(severity), file, line); vfprintf(stderr, format, args); fputc('\n', stderr); - - va_end(args); } #endif diff --git a/test/core/statistics/log_tests.c b/test/core/statistics/census_log_tests.c similarity index 99% rename from test/core/statistics/log_tests.c rename to test/core/statistics/census_log_tests.c index f0cbdbdf707511549361195ffb85111cf9f6cd96..179d1cda8268f54fde723432437ed7bd50bd315d 100644 --- a/test/core/statistics/log_tests.c +++ b/test/core/statistics/census_log_tests.c @@ -31,7 +31,7 @@ * */ -#include "src/core/statistics/log.h" +#include "src/core/statistics/census_log.h" #include <stdio.h> #include <stdlib.h> #include <string.h> diff --git a/test/core/statistics/log_tests.h b/test/core/statistics/census_log_tests.h similarity index 100% rename from test/core/statistics/log_tests.h rename to test/core/statistics/census_log_tests.h diff --git a/test/core/statistics/multiple_writers_circular_buffer_test.c b/test/core/statistics/multiple_writers_circular_buffer_test.c index 0cd0d78df29f9a5d3e5277a6190bbb19d01f8f78..298900a6612b0041c9f7c0eccedf505cd85bcfee 100644 --- a/test/core/statistics/multiple_writers_circular_buffer_test.c +++ b/test/core/statistics/multiple_writers_circular_buffer_test.c @@ -31,7 +31,7 @@ * */ -#include "test/core/statistics/log_tests.h" +#include "test/core/statistics/census_log_tests.h" #include <stdlib.h> diff --git a/test/core/statistics/multiple_writers_test.c b/test/core/statistics/multiple_writers_test.c index b1f3be4eba516c812f1cd1a4ff8faf1d65f99442..ae6fd956514881c16d08143feeba4c486fa4d017 100644 --- a/test/core/statistics/multiple_writers_test.c +++ b/test/core/statistics/multiple_writers_test.c @@ -31,7 +31,7 @@ * */ -#include "test/core/statistics/log_tests.h" +#include "test/core/statistics/census_log_tests.h" #include <stdlib.h> diff --git a/test/core/statistics/performance_test.c b/test/core/statistics/performance_test.c index 9197dd5c735e12f9cd054ef6146ea8d84aac0ff0..40fe4c59114590fe7efde3b568d72b53c376efdd 100644 --- a/test/core/statistics/performance_test.c +++ b/test/core/statistics/performance_test.c @@ -31,7 +31,7 @@ * */ -#include "log_tests.h" +#include "test/core/statistics/census_log_tests.h" #include <stdlib.h> diff --git a/test/core/statistics/quick_test.c b/test/core/statistics/quick_test.c index fe2b89a9a46b923d56453eb10970c48934859e93..8df32cf111768b631b111efa49051b9991613179 100644 --- a/test/core/statistics/quick_test.c +++ b/test/core/statistics/quick_test.c @@ -31,7 +31,7 @@ * */ -#include "log_tests.h" +#include "test/core/statistics/census_log_tests.h" #include <stdlib.h> diff --git a/vsprojects/vs2013/grpc.vcxproj b/vsprojects/vs2013/grpc.vcxproj index 4a0c2a1025a733e0ebb9f4cd610888b1c2ada19f..c01322bc9c23851f453940c281ea6ce83de5b452 100644 --- a/vsprojects/vs2013/grpc.vcxproj +++ b/vsprojects/vs2013/grpc.vcxproj @@ -123,7 +123,7 @@ <ClInclude Include="..\..\src\core\statistics\census_interface.h" /> <ClInclude Include="..\..\src\core\statistics\census_rpc_stats.h" /> <ClInclude Include="..\..\src\core\statistics\hash_table.h" /> - <ClInclude Include="..\..\src\core\statistics\log.h" /> + <ClInclude Include="..\..\src\core\statistics\census_log.h" /> <ClInclude Include="..\..\src\core\statistics\window_stats.h" /> <ClInclude Include="..\..\src\core\surface\call.h" /> <ClInclude Include="..\..\src\core\surface\channel.h" /> @@ -246,7 +246,7 @@ </ClCompile> <ClCompile Include="..\..\src\core\statistics\hash_table.c"> </ClCompile> - <ClCompile Include="..\..\src\core\statistics\log.c"> + <ClCompile Include="..\..\src\core\statistics\census_log.c"> </ClCompile> <ClCompile Include="..\..\src\core\statistics\window_stats.c"> </ClCompile>