fix bug in log upload
This commit is contained in:
@@ -36,45 +36,266 @@ extern pthread_mutex_t warnListMutex;
|
||||
extern pthread_mutex_t normalListMutex;
|
||||
extern pthread_mutex_t debugListMutex;
|
||||
|
||||
// **声明原始 echo_msgX(),让编译器知道它们存在**
|
||||
void real_echo_msg(const char *format, ...);
|
||||
|
||||
// **拦截所有 `echo_msgX()`,让它同时存入 `normalList`**
|
||||
#define echo_msgX(format, ...) \
|
||||
do { \
|
||||
char buffer[1024]; \
|
||||
snprintf(buffer, sizeof(buffer), format, ##__VA_ARGS__); \
|
||||
\
|
||||
/* ✅ 先打印到 Shell,确保不会卡死 */ \
|
||||
printf("%s", buffer); \
|
||||
fflush(stdout); /* ✅ 立即刷新,防止标准输出缓存 */ \
|
||||
\
|
||||
/* ✅ 先创建日志副本,避免锁住 `normalList` 过久 */ \
|
||||
std::string logEntry(buffer); \
|
||||
\
|
||||
/* ✅ 仅在 `normalList` 操作时加锁,避免死锁 */ \
|
||||
pthread_mutex_lock(&normalListMutex); \
|
||||
normalList.push_back(logEntry); \
|
||||
pthread_mutex_unlock(&normalListMutex); \
|
||||
} while (0)
|
||||
|
||||
// **宏自动展开不同的 `echo_msg` 变体**
|
||||
#define echo_msg1 echo_msgX
|
||||
#define echo_msg2 echo_msgX
|
||||
#define echo_msg3 echo_msgX
|
||||
#define echo_msg4 echo_msgX
|
||||
#define echo_msg5 echo_msgX
|
||||
#define echo_msg6 echo_msgX
|
||||
#define echo_msg7 echo_msgX
|
||||
#define echo_msg8 echo_msgX
|
||||
#define echo_msg9 echo_msgX
|
||||
#define echo_msg10 echo_msgX
|
||||
#define echo_msg11 echo_msgX
|
||||
// **如果有更多的 `echo_msgX()`,继续定义**
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
void echo_msg_debugexy(const char *file_name, int line_no, const char *fmt, ...);
|
||||
void echo_msg_warnexy(const char *file_name, int line_no, const char *fmt, ...);
|
||||
void echo_msg_errexy(const char *file_name, int line_no, int rv, const char *fmt, ...);
|
||||
|
||||
|
||||
#define echo_msg_debugexy(file_name, line_no, ...) \
|
||||
echo_msg_debugexy(file_name, line_no, __VA_ARGS__)
|
||||
|
||||
#define echo_msg_warnexy(file_name, line_no, ...) \
|
||||
echo_msg_warnexy(file_name, line_no, __VA_ARGS__)
|
||||
|
||||
#define echo_msg_errexy(file_name, line_no, rv, ...) \
|
||||
echo_msg_errexy(file_name, line_no, rv, __VA_ARGS__)
|
||||
|
||||
// ======================= echo_warnX =======================
|
||||
#ifdef echo_warn
|
||||
#undef echo_warn
|
||||
#endif
|
||||
#define echo_warn(s) \
|
||||
echo_msg_warnexy(__FILE__, __LINE__, ("%s"), s)
|
||||
|
||||
#ifdef echo_warn1
|
||||
#undef echo_warn1
|
||||
#endif
|
||||
#define echo_warn1(fmt, s0) \
|
||||
echo_msg_warnexy(__FILE__, __LINE__, (fmt), (s0))
|
||||
|
||||
#ifdef echo_warn2
|
||||
#undef echo_warn2
|
||||
#endif
|
||||
#define echo_warn2(fmt, s0, s1) \
|
||||
echo_msg_warnexy(__FILE__, __LINE__, (fmt), (s0), (s1))
|
||||
|
||||
#ifdef echo_warn3
|
||||
#undef echo_warn3
|
||||
#endif
|
||||
#define echo_warn3(fmt, s0, s1, s2) \
|
||||
echo_msg_warnexy(__FILE__, __LINE__, (fmt), (s0), (s1), (s2))
|
||||
|
||||
#ifdef echo_warn4
|
||||
#undef echo_warn4
|
||||
#endif
|
||||
#define echo_warn4(fmt, s0, s1, s2, s3) \
|
||||
echo_msg_warnexy(__FILE__, __LINE__, (fmt), (s0), (s1), (s2), (s3))
|
||||
|
||||
#ifdef echo_warn5
|
||||
#undef echo_warn5
|
||||
#endif
|
||||
#define echo_warn5(fmt, s0, s1, s2, s3, s4) \
|
||||
echo_msg_warnexy(__FILE__, __LINE__, (fmt), (s0), (s1), (s2), (s3), (s4))
|
||||
|
||||
#ifdef echo_warn6
|
||||
#undef echo_warn6
|
||||
#endif
|
||||
#define echo_warn6(fmt, s0, s1, s2, s3, s4, s5) \
|
||||
echo_msg_warnexy(__FILE__, __LINE__, (fmt), (s0), (s1), (s2), (s3), (s4), (s5))
|
||||
|
||||
#ifdef echo_warn7
|
||||
#undef echo_warn7
|
||||
#endif
|
||||
#define echo_warn7(fmt, s0, s1, s2, s3, s4, s5, s6) \
|
||||
echo_msg_warnexy(__FILE__, __LINE__, (fmt), (s0), (s1), (s2), (s3), (s4), (s5), (s6))
|
||||
|
||||
#ifdef echo_warn8
|
||||
#undef echo_warn8
|
||||
#endif
|
||||
#define echo_warn8(fmt, s0, s1, s2, s3, s4, s5, s6, s7) \
|
||||
echo_msg_warnexy(__FILE__, __LINE__, (fmt), (s0), (s1), (s2), (s3), (s4), (s5), (s6), (s7))
|
||||
|
||||
#ifdef echo_warn9
|
||||
#undef echo_warn9
|
||||
#endif
|
||||
#define echo_warn9(fmt, s0, s1, s2, s3, s4, s5, s6, s7, s8) \
|
||||
echo_msg_warnexy(__FILE__, __LINE__, (fmt), (s0), (s1), (s2), (s3), (s4), (s5), (s6), (s7), (s8))
|
||||
|
||||
#ifdef echo_warn10
|
||||
#undef echo_warn10
|
||||
#endif
|
||||
#define echo_warn10(fmt, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9) \
|
||||
echo_msg_warnexy(__FILE__, __LINE__, (fmt), (s0), (s1), (s2), (s3), (s4), (s5), (s6), (s7), (s8), (s9))
|
||||
|
||||
#ifdef echo_warn11
|
||||
#undef echo_warn11
|
||||
#endif
|
||||
#define echo_warn11(fmt, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10) \
|
||||
echo_msg_warnexy(__FILE__, __LINE__, (fmt), (s0), (s1), (s2), (s3), (s4), (s5), (s6), (s7), (s8), (s9), (s10))
|
||||
|
||||
#ifdef echo_warn12
|
||||
#undef echo_warn12
|
||||
#endif
|
||||
#define echo_warn12(fmt, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11) \
|
||||
echo_msg_warnexy(__FILE__, __LINE__, (fmt), (s0), (s1), (s2), (s3), (s4), (s5), (s6), (s7), (s8), (s9), (s10), (s11))
|
||||
|
||||
// ======================= echo_errX =======================
|
||||
#ifdef echo_err
|
||||
#undef echo_err
|
||||
#endif
|
||||
#define echo_err(s, rv) \
|
||||
echo_msg_errexy(__FILE__, __LINE__, (rv), ("%s"), (s))
|
||||
|
||||
#ifdef echo_errg
|
||||
#undef echo_errg
|
||||
#endif
|
||||
#define echo_errg(s) \
|
||||
echo_msg_errexy(__FILE__, __LINE__, (APR_EGENERAL), ("%s"), (s))
|
||||
|
||||
#ifdef echo_err1
|
||||
#undef echo_err1
|
||||
#endif
|
||||
#define echo_err1(fmt, rv, s1) \
|
||||
echo_msg_errexy(__FILE__, __LINE__, (rv), (fmt), (s1))
|
||||
|
||||
#ifdef echo_err2
|
||||
#undef echo_err2
|
||||
#endif
|
||||
#define echo_err2(fmt, rv, s1, s2) \
|
||||
echo_msg_errexy(__FILE__, __LINE__, (rv), (fmt), (s1), (s2))
|
||||
|
||||
#ifdef echo_err3
|
||||
#undef echo_err3
|
||||
#endif
|
||||
#define echo_err3(fmt, rv, s1, s2, s3) \
|
||||
echo_msg_errexy(__FILE__, __LINE__, (rv), (fmt), (s1), (s2), (s3))
|
||||
|
||||
#ifdef echo_err4
|
||||
#undef echo_err4
|
||||
#endif
|
||||
#define echo_err4(fmt, rv, s1, s2, s3, s4) \
|
||||
echo_msg_errexy(__FILE__, __LINE__, (rv), (fmt), (s1), (s2), (s3), (s4))
|
||||
|
||||
#ifdef echo_err5
|
||||
#undef echo_err5
|
||||
#endif
|
||||
#define echo_err5(fmt, rv, s1, s2, s3, s4, s5) \
|
||||
echo_msg_errexy(__FILE__, __LINE__, (rv), (fmt), (s1), (s2), (s3), (s4), (s5))
|
||||
|
||||
#ifdef echo_err6
|
||||
#undef echo_err6
|
||||
#endif
|
||||
#define echo_err6(fmt, rv, s1, s2, s3, s4, s5, s6) \
|
||||
echo_msg_errexy(__FILE__, __LINE__, (rv), (fmt), (s1), (s2), (s3), (s4), (s5), (s6))
|
||||
|
||||
#ifdef echo_err7
|
||||
#undef echo_err7
|
||||
#endif
|
||||
#define echo_err7(fmt, rv, s1, s2, s3, s4, s5, s6, s7) \
|
||||
echo_msg_errexy(__FILE__, __LINE__, (rv), (fmt), (s1), (s2), (s3), (s4), (s5), (s6), (s7))
|
||||
|
||||
#ifdef echo_err8
|
||||
#undef echo_err8
|
||||
#endif
|
||||
#define echo_err8(fmt, rv, s1, s2, s3, s4, s5, s6, s7, s8) \
|
||||
echo_msg_errexy(__FILE__, __LINE__, (rv), (fmt), (s1), (s2), (s3), (s4), (s5), (s6), (s7), (s8))
|
||||
|
||||
#ifdef echo_err9
|
||||
#undef echo_err9
|
||||
#endif
|
||||
#define echo_err9(fmt, rv, s1, s2, s3, s4, s5, s6, s7, s8, s9) \
|
||||
echo_msg_errexy(__FILE__, __LINE__, (rv), (fmt), (s1), (s2), (s3), (s4), (s5), (s6), (s7), (s8), (s9))
|
||||
|
||||
#ifdef echo_err10
|
||||
#undef echo_err10
|
||||
#endif
|
||||
#define echo_err10(fmt, rv, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10) \
|
||||
echo_msg_errexy(__FILE__, __LINE__, (rv), (fmt), (s1), (s2), (s3), (s4), (s5), (s6), (s7), (s8), (s9), (s10))
|
||||
|
||||
#ifdef echo_err11
|
||||
#undef echo_err11
|
||||
#endif
|
||||
#define echo_err11(fmt, rv, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11) \
|
||||
echo_msg_errexy(__FILE__, __LINE__, (rv), (fmt), (s1), (s2), (s3), (s4), (s5), (s6), (s7), (s8), (s9), (s10), (s11))
|
||||
|
||||
#ifdef echo_err12
|
||||
#undef echo_err12
|
||||
#endif
|
||||
#define echo_err12(fmt, rv, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12) \
|
||||
echo_msg_errexy(__FILE__, __LINE__, (rv), (fmt), (s1), (s2), (s3), (s4), (s5), (s6), (s7), (s8), (s9), (s10), (s11), (s12))
|
||||
|
||||
// ======================= echo_msgX =======================
|
||||
#ifdef echo_msg
|
||||
#undef echo_msg
|
||||
#endif
|
||||
#define echo_msg(s) \
|
||||
echo_msg_debugexy(__FILE__, __LINE__, ("%s"), (s))
|
||||
|
||||
#ifdef echo_msg1
|
||||
#undef echo_msg1
|
||||
#endif
|
||||
#define echo_msg1(fmt, s1) \
|
||||
echo_msg_debugexy(__FILE__, __LINE__, (fmt), (s1))
|
||||
|
||||
#ifdef echo_msg2
|
||||
#undef echo_msg2
|
||||
#endif
|
||||
#define echo_msg2(fmt, s1, s2) \
|
||||
echo_msg_debugexy(__FILE__, __LINE__, (fmt), (s1), (s2))
|
||||
|
||||
#ifdef echo_msg3
|
||||
#undef echo_msg3
|
||||
#endif
|
||||
#define echo_msg3(fmt, s1, s2, s3) \
|
||||
echo_msg_debugexy(__FILE__, __LINE__, (fmt), (s1), (s2), (s3))
|
||||
|
||||
#ifdef echo_msg4
|
||||
#undef echo_msg4
|
||||
#endif
|
||||
#define echo_msg4(fmt, s1, s2, s3, s4) \
|
||||
echo_msg_debugexy(__FILE__, __LINE__, (fmt), (s1), (s2), (s3), (s4))
|
||||
|
||||
#ifdef echo_msg5
|
||||
#undef echo_msg5
|
||||
#endif
|
||||
#define echo_msg5(fmt, s1, s2, s3, s4, s5) \
|
||||
echo_msg_debugexy(__FILE__, __LINE__, (fmt), (s1), (s2), (s3), (s4), (s5))
|
||||
|
||||
#ifdef echo_msg6
|
||||
#undef echo_msg6
|
||||
#endif
|
||||
#define echo_msg6(fmt, s1, s2, s3, s4, s5, s6) \
|
||||
echo_msg_debugexy(__FILE__, __LINE__, (fmt), (s1), (s2), (s3), (s4), (s5), (s6))
|
||||
|
||||
#ifdef echo_msg7
|
||||
#undef echo_msg7
|
||||
#endif
|
||||
#define echo_msg7(fmt, s1, s2, s3, s4, s5, s6, s7) \
|
||||
echo_msg_debugexy(__FILE__, __LINE__, (fmt), (s1), (s2), (s3), (s4), (s5), (s6), (s7))
|
||||
|
||||
#ifdef echo_msg8
|
||||
#undef echo_msg8
|
||||
#endif
|
||||
#define echo_msg8(fmt, s1, s2, s3, s4, s5, s6, s7, s8) \
|
||||
echo_msg_debugexy(__FILE__, __LINE__, (fmt), (s1), (s2), (s3), (s4), (s5), (s6), (s7), (s8))
|
||||
|
||||
#ifdef echo_msg9
|
||||
#undef echo_msg9
|
||||
#endif
|
||||
#define echo_msg9(fmt, s1, s2, s3, s4, s5, s6, s7, s8, s9) \
|
||||
echo_msg_debugexy(__FILE__, __LINE__, (fmt), (s1), (s2), (s3), (s4), (s5), (s6), (s7), (s8), (s9))
|
||||
|
||||
#ifdef echo_msg10
|
||||
#undef echo_msg10
|
||||
#endif
|
||||
#define echo_msg10(fmt, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10) \
|
||||
echo_msg_debugexy(__FILE__, __LINE__, (fmt), (s1), (s2), (s3), (s4), (s5), (s6), (s7), (s8), (s9), (s10))
|
||||
|
||||
#ifdef echo_msg11
|
||||
#undef echo_msg11
|
||||
#endif
|
||||
#define echo_msg11(fmt, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11) \
|
||||
echo_msg_debugexy(__FILE__, __LINE__, (fmt), (s1), (s2), (s3), (s4), (s5), (s6), (s7), (s8), (s9), (s10), (s11))
|
||||
|
||||
#ifdef echo_msg12
|
||||
#undef echo_msg12
|
||||
#endif
|
||||
#define echo_msg12(fmt, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12) \
|
||||
echo_msg_debugexy(__FILE__, __LINE__, (fmt), (s1), (s2), (s3), (s4), (s5), (s6), (s7), (s8), (s9), (s10), (s11), (s12))
|
||||
|
||||
// 自定义的 printf 函数
|
||||
int customPrintf(const char* format, ...);
|
||||
#ifdef __cplusplus
|
||||
|
||||
Reference in New Issue
Block a user