From 46e4f252dcc09b40f71635aaeb80476635aa8076 Mon Sep 17 00:00:00 2001 From: David Reiss Date: Wed, 6 Oct 2010 17:10:53 +0000 Subject: [PATCH] THRIFT-926. cpp: remove auto-stringification in TLogging.h The T_DEBUG* and T_ERROR* macros used preprocessor stringification to stringify the format string argument. This was weird and unintuitive. With the old behavior: - Quotes surrounding the format string were included in the message: T_DEBUG("this is a test") --> expanded to "\"this is a test\"" - Backslashes in the string are escaped so they print literally: T_DEBUG("foo\nbar") --> expanded to "\"foo\\nbar\"" - Standard fixed-width integer format macros don't work: T_DEBUG("x: %" PRIi64, x) --> expanded to "\"x: %\" PRIi64" The last item is particularly problematic, since it prevents 64-bit values from being logged portably. With the new code, the following will no longer compile: T_DEBUG(this is my log message: %d, 5) I don't think that is a bad thing, though. git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@1005170 13f79535-47bb-0310-9956-ffa450edef68 --- lib/cpp/src/TLogging.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/cpp/src/TLogging.h b/lib/cpp/src/TLogging.h index 2c23f0aa..934e8fc1 100644 --- a/lib/cpp/src/TLogging.h +++ b/lib/cpp/src/TLogging.h @@ -63,7 +63,7 @@ #if T_GLOBAL_DEBUGGING_LEVEL > 0 #define T_DEBUG(format_string,...) \ if (T_GLOBAL_DEBUGGING_LEVEL > 0) { \ - fprintf(stderr,"[%s,%d] " #format_string " \n", __FILE__, __LINE__,##__VA_ARGS__); \ + fprintf(stderr,"[%s,%d] " format_string " \n", __FILE__, __LINE__,##__VA_ARGS__); \ } #else #define T_DEBUG(format_string,...) @@ -84,7 +84,7 @@ time(&now); \ ctime_r(&now, dbgtime); \ dbgtime[24] = '\0'; \ - fprintf(stderr,"[%s,%d] [%s] " #format_string " \n", __FILE__, __LINE__,dbgtime,##__VA_ARGS__); \ + fprintf(stderr,"[%s,%d] [%s] " format_string " \n", __FILE__, __LINE__,dbgtime,##__VA_ARGS__); \ } \ } #else @@ -101,7 +101,7 @@ */ #define T_DEBUG_L(level, format_string,...) \ if ((level) > 0) { \ - fprintf(stderr,"[%s,%d] " #format_string " \n", __FILE__, __LINE__,##__VA_ARGS__); \ + fprintf(stderr,"[%s,%d] " format_string " \n", __FILE__, __LINE__,##__VA_ARGS__); \ } @@ -117,7 +117,7 @@ time(&now); \ ctime_r(&now, dbgtime); \ dbgtime[24] = '\0'; \ - fprintf(stderr,"[%s,%d] [%s] ERROR: " #format_string " \n", __FILE__, __LINE__,dbgtime,##__VA_ARGS__); \ + fprintf(stderr,"[%s,%d] [%s] ERROR: " format_string " \n", __FILE__, __LINE__,dbgtime,##__VA_ARGS__); \ } @@ -134,7 +134,7 @@ time(&now); \ ctime_r(&now, dbgtime); \ dbgtime[24] = '\0'; \ - fprintf(stderr,"[%s,%d] [%s] ERROR: Going to abort " #format_string " \n", __FILE__, __LINE__,dbgtime,##__VA_ARGS__); \ + fprintf(stderr,"[%s,%d] [%s] ERROR: Going to abort " format_string " \n", __FILE__, __LINE__,dbgtime,##__VA_ARGS__); \ exit(1); \ } @@ -153,7 +153,7 @@ time(&now); \ ctime_r(&now, dbgtime); \ dbgtime[24] = '\0'; \ - fprintf(stderr,"[%s] " #format_string " \n", dbgtime,##__VA_ARGS__); \ + fprintf(stderr,"[%s] " format_string " \n", dbgtime,##__VA_ARGS__); \ } \ } #else -- 2.17.1