aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar nnoble <nnoble@google.com>2014-12-12 10:48:34 -0800
committerGravatar Nicolas Noble <nnoble@google.com>2014-12-12 16:20:22 -0800
commit8a67b5c281d65c308fdfc8c898c7c19673dca9cb (patch)
tree8a854fad4312cc221d5a746703191624d19facd8
parent82e275ffaf7210b4e0721aec70ba8c4807440da3 (diff)
Tweaking log calls a bit.
-) Introducing gpr_vlog so to spare a few vsprintf later (at least one for now) -) Renaming statistics/log.* to statistics/census_log.* to avoid collisions. Change on 2014/12/12 by nnoble <nnoble@google.com> ------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=81995756
-rw-r--r--Makefile4
-rw-r--r--build.json4
-rw-r--r--include/grpc/support/log.h5
-rw-r--r--src/core/channel/connected_channel.c5
-rw-r--r--src/core/statistics/census_log.c (renamed from src/core/statistics/log.c)2
-rw-r--r--src/core/statistics/census_log.h (renamed from src/core/statistics/log.h)0
-rw-r--r--src/core/support/log.c10
-rw-r--r--src/core/support/log_android.c7
-rw-r--r--src/core/support/log_linux.c8
-rw-r--r--src/core/support/log_posix.c8
-rw-r--r--src/core/support/log_win32.c9
-rw-r--r--test/core/statistics/census_log_tests.c (renamed from test/core/statistics/log_tests.c)2
-rw-r--r--test/core/statistics/census_log_tests.h (renamed from test/core/statistics/log_tests.h)0
-rw-r--r--test/core/statistics/multiple_writers_circular_buffer_test.c2
-rw-r--r--test/core/statistics/multiple_writers_test.c2
-rw-r--r--test/core/statistics/performance_test.c2
-rw-r--r--test/core/statistics/quick_test.c2
-rw-r--r--vsprojects/vs2013/grpc.vcxproj4
18 files changed, 36 insertions, 40 deletions
diff --git a/Makefile b/Makefile
index 03de0aaae2..80a2e5142f 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 e6158262ff..b4dc9b66bf 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 b79d661f65..5d0b790867 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 5dc4d7a5d4..8581fb41d6 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
index 43a8653de6..9de9d2efb7 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
index e9c745cac0..e9c745cac0 100644
--- a/src/core/statistics/log.h
+++ b/src/core/statistics/census_log.h
diff --git a/src/core/support/log.c b/src/core/support/log.c
index 79321f7ffe..b9e2897efc 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 9e2b03471f..4c83e09914 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 e39e2cc166..322ff07dd9 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 68882f7e89..b47c433cd7 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 fb2fc0c239..e6567dca7e 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
index f0cbdbdf70..179d1cda82 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
index 10993ac76f..10993ac76f 100644
--- a/test/core/statistics/log_tests.h
+++ b/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 0cd0d78df2..298900a661 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 b1f3be4eba..ae6fd95651 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 9197dd5c73..40fe4c5911 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 fe2b89a9a4..8df32cf111 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 4a0c2a1025..c01322bc9c 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>