kou commented on PR #3187: URL: https://github.com/apache/thrift/pull/3187#issuecomment-3567154183
OK. How about using `#define XXX(...)` + `fprintf(stderr, __VA_ARGS__)`
instead of `#define XXX(format_string, ...)` + `fprintf(stderr, format_string,
##__VA_ARGS__)`? It still can reject `XXX()` (but error message is changed) and
accept `XXX("...")`.
```diff
diff --git a/lib/cpp/src/thrift/TLogging.h b/lib/cpp/src/thrift/TLogging.h
index 07ff030f7..c4935f757 100644
--- a/lib/cpp/src/thrift/TLogging.h
+++ b/lib/cpp/src/thrift/TLogging.h
@@ -53,9 +53,11 @@
* @param format_string
*/
#if T_GLOBAL_DEBUGGING_LEVEL > 0
-#define T_DEBUG(format_string, ...)
\
+#define T_DEBUG(...)
\
if (T_GLOBAL_DEBUGGING_LEVEL > 0) {
\
- fprintf(stderr, "[%s,%d] " format_string " \n", __FILE__, __LINE__,
##__VA_ARGS__); \
+ fprintf(stderr, "[%s,%d] ", __FILE__, __LINE__);
\
+ fprintf(stderr, __VA_ARGS__);
\
+ fprintf(stderr, " \n");
\
}
#else
#define T_DEBUG(format_string, ...)
@@ -67,7 +69,7 @@
* @param string format_string input: printf style format string
*/
#if T_GLOBAL_DEBUGGING_LEVEL > 0
-#define T_DEBUG_T(format_string, ...)
\
+#define T_DEBUG_T(...)
\
{
\
if (T_GLOBAL_DEBUGGING_LEVEL > 0) {
\
time_t now;
\
@@ -76,11 +78,12 @@
THRIFT_CTIME_R(&now, dbgtime);
\
dbgtime[24] = '\0';
\
fprintf(stderr,
\
- "[%s,%d] [%s] " format_string " \n",
\
+ "[%s,%d] [%s] ",
\
__FILE__,
\
__LINE__,
\
- dbgtime,
\
- ##__VA_ARGS__);
\
+ dbgtime);
\
+ fprintf(stderr, __VA_ARGS__);
\
+ fprintf(stderr, " \n");
\
}
\
}
#else
@@ -94,9 +97,11 @@
* @param int level: specified debug level
* @param string format_string input: format string
*/
-#define T_DEBUG_L(level, format_string, ...)
\
+#define T_DEBUG_L(level, ...)
\
if ((level) > 0) {
\
- fprintf(stderr, "[%s,%d] " format_string " \n", __FILE__, __LINE__,
##__VA_ARGS__); \
+ fprintf(stderr, "[%s,%d] ", __FILE__, __LINE__);
\
+ fprintf(stderr, __VA_ARGS__);
\
+ fprintf(stderr, " \n");
\
}
/**
@@ -104,7 +109,7 @@
*
* @param string format_string input: printf style format string
*/
-#define T_ERROR(format_string, ...)
\
+#define T_ERROR(...)
\
{
\
time_t now;
\
char dbgtime[26];
\
@@ -112,11 +117,12 @@
THRIFT_CTIME_R(&now, dbgtime);
\
dbgtime[24] = '\0';
\
fprintf(stderr,
\
- "[%s,%d] [%s] ERROR: " format_string " \n",
\
+ "[%s,%d] [%s] ERROR: ",
\
__FILE__,
\
__LINE__,
\
- dbgtime,
\
- ##__VA_ARGS__);
\
+ dbgtime);
\
+ fprintf(stderr, __VA_ARGS__);
\
+ fprintf(stderr, " \n");
\
}
/**
@@ -125,7 +131,7 @@
*
* @param string format_string input: printf style format string
*/
-#define T_ERROR_ABORT(format_string, ...)
\
+#define T_ERROR_ABORT(...)
\
{
\
time_t now;
\
char dbgtime[26];
\
@@ -133,11 +139,12 @@
THRIFT_CTIME_R(&now, dbgtime);
\
dbgtime[24] = '\0';
\
fprintf(stderr,
\
- "[%s,%d] [%s] ERROR: Going to abort " format_string " \n",
\
+ "[%s,%d] [%s] ERROR: Going to abort ",
\
__FILE__,
\
__LINE__,
\
- dbgtime,
\
- ##__VA_ARGS__);
\
+ dbgtime);
\
+ fprintf(stderr, __VA_ARGS__);
\
+ fprintf(stderr, " \n");
\
exit(1);
\
}
@@ -147,7 +154,7 @@
* @param string format_string input: printf style format string
*/
#if T_GLOBAL_LOGGING_LEVEL > 0
-#define T_LOG_OPER(format_string, ...)
\
+#define T_LOG_OPER(...)
\
{
\
if (T_GLOBAL_LOGGING_LEVEL > 0) {
\
time_t now;
\
@@ -155,7 +162,9 @@
time(&now);
\
THRIFT_CTIME_R(&now, dbgtime);
\
dbgtime[24] = '\0';
\
- fprintf(stderr, "[%s] " format_string " \n", dbgtime, ##__VA_ARGS__);
\
+ fprintf(stderr, "[%s] ", dbgtime);
\
+ fprintf(stderr, __VA_ARGS__);
\
+ fprintf(stderr, " \n");
\
}
\
}
#else
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
