You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by dr...@apache.org on 2010/10/06 19:10:53 UTC

svn commit: r1005170 - /incubator/thrift/trunk/lib/cpp/src/TLogging.h

Author: dreiss
Date: Wed Oct  6 17:10:53 2010
New Revision: 1005170

URL: http://svn.apache.org/viewvc?rev=1005170&view=rev
Log:
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.

Modified:
    incubator/thrift/trunk/lib/cpp/src/TLogging.h

Modified: incubator/thrift/trunk/lib/cpp/src/TLogging.h
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/cpp/src/TLogging.h?rev=1005170&r1=1005169&r2=1005170&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/cpp/src/TLogging.h (original)
+++ incubator/thrift/trunk/lib/cpp/src/TLogging.h Wed Oct  6 17:10:53 2010
@@ -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