fix bug in log upload

This commit is contained in:
lnk
2025-03-04 17:29:04 +08:00
parent 87f0a48ad7
commit 1df5385fc9
16 changed files with 434 additions and 80 deletions

View File

@@ -203,6 +203,7 @@ const int MAX_CPUNO = 10;
//lnk20250121<32>ն<EFBFBD>̨<EFBFBD><CCA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int IED_COUNT = 300; //Ĭ<><C4AC>300
extern int INITFLAG;
//WW 2-23-08-20 add start
otl_connect db; //OTL<54><4C><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD>Ӷ<EFBFBD><D3B6><EFBFBD> WW 2023-08-20
@@ -11789,7 +11790,7 @@ void ledger(const char* terminal_id, QIODevice* outputDevice) {
if(ied != NULL){
ied_usr = (ied_usr_t*)ied->usr_ext;
if (ied_usr != NULL && (terminal_id == NULL || strcmp(ied_usr->terminal_id, terminal_id) == 0)) {
printLedgerinshell(*ied_usr, outputDevice); // ʹ<><CAB9> QIODevice <20><><EFBFBD><EFBFBD>
//printLedgerinshell(*ied_usr, outputDevice); // ʹ<><CAB9> QIODevice <20><><EFBFBD><EFBFBD>
//std::cout << "!!! print to log !!!"<< std::endl;
//printLedger(*ied_usr);
found = true;
@@ -11829,6 +11830,9 @@ void value_print(const char *variableName, QTcpSocket *clientSocket) {
} else if (strcmp(variableName, "log") == 0) {
sprintf(buffer, "showinshellflag = %d,debugOutputEnabled = %d,normalOutputEnabled = %d,warnOutputEnabled = %d,errorOutputEnabled = %d", showinshellflag,debugOutputEnabled,normalOutputEnabled,warnOutputEnabled,errorOutputEnabled);
clientSocket->write(buffer);
}else if (strcmp(variableName, "init") == 0) {
sprintf(buffer, "INITFLAG = %d",INITFLAG);
clientSocket->write(buffer);
}else {
clientSocket->write("Unknown variable name\n> ");
}
@@ -15496,31 +15500,39 @@ void myQtMsgHandler(QtMsgType type, const char *msg)
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Σ<EFBFBD><CEA3><EFBFBD>д<EFBFBD><D0B4> debugList
if (debugOutputEnabled) {
pthread_mutex_lock(&debugListMutex);
debugList.push_back(msg); // <20><> const char* ת<><D7AA>Ϊ std::string <20>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>
debugList.push_back(msg);
pthread_mutex_unlock(&debugListMutex);
}
// ͬʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> stderr<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD>
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
FILE* output = nullptr;
const char* typeStr = "";
switch (type) {
case QtDebugMsg:
typeStr = "Debug";
output = stdout; // Debug <20>߱<EFBFBD>׼<EFBFBD><D7BC><EFBFBD><EFBFBD>
break;
case QtWarningMsg:
typeStr = "Warning";
output = stderr; // Warning <20>߱<EFBFBD>׼<EFBFBD><D7BC><EFBFBD><EFBFBD>
break;
case QtCriticalMsg:
typeStr = "Critical";
output = stderr; // Critical <20>߱<EFBFBD>׼<EFBFBD><D7BC><EFBFBD><EFBFBD>
break;
case QtFatalMsg:
typeStr = "Fatal";
output = stderr; // Fatal <20>߱<EFBFBD>׼<EFBFBD><D7BC><EFBFBD><EFBFBD>
break;
}
fprintf(stderr, "[%s] %s\n", typeStr, msg);
fflush(stderr);
if (type == QtFatalMsg)
fprintf(output, "[%s] %s\n", typeStr, msg);
fflush(output);
// Fatal ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD>
if (type == QtFatalMsg) {
abort();
}
}
// ------------------ <20>Զ<EFBFBD><D4B6><EFBFBD> printf <20><><EFBFBD><EFBFBD> ------------------
@@ -15545,16 +15557,62 @@ int customPrintf(const char* format, ...)
return written;
}
// **ԭʼ `echo_msgX()` <20><>ʵ<EFBFBD><CAB5>**
void real_echo_msg(const char *format, ...) {
char buffer[1024];
va_list args;
va_start(args, format);
vsnprintf(buffer, sizeof(buffer), format, args);
va_end(args);
///////////////////////////////////////////////////////////////////////////////
void echo_msg_errexy(const char *file_name, int line_no, int rv, const char *fmt, ...) {
char __buf[1024];
va_list __ap;
va_start(__ap, fmt);
vsnprintf(__buf, sizeof(__buf), fmt, __ap);
va_end(__ap);
printf("%s", buffer);
fflush(stdout); // ? ȷ<><C8B7><EFBFBD><EFBFBD>׼<EFBFBD><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˢ<EFBFBD><CBA2>
// <20>ն<EFBFBD><D5B6><EFBFBD><EFBFBD><EFBFBD>
printf("[ERROR] rv=%d %s:%d => %s", rv, file_name, line_no, __buf);
fflush(stdout);
// д<><D0B4> errorList
if (errorOutputEnabled) {
pthread_mutex_lock(&errorListMutex);
errorList.push_back(std::string(__buf));
pthread_mutex_unlock(&errorListMutex);
}
}
void echo_msg_warnexy(const char *file_name, int line_no, const char *fmt, ...) {
char __buf[1024];
va_list __ap;
va_start(__ap, fmt);
vsnprintf(__buf, sizeof(__buf), fmt, __ap);
va_end(__ap);
// <20>ն<EFBFBD><D5B6><EFBFBD><EFBFBD><EFBFBD>
printf("[WARN ] %s:%d => %s", file_name, line_no, __buf);
fflush(stdout);
// д<><D0B4> warnList
if (warnOutputEnabled) {
pthread_mutex_lock(&warnListMutex);
warnList.push_back(std::string(__buf));
pthread_mutex_unlock(&warnListMutex);
}
}
void echo_msg_debugexy(const char *file_name, int line_no, const char *fmt, ...) {
char __buf[1024];
va_list __ap;
va_start(__ap, fmt);
vsnprintf(__buf, sizeof(__buf), fmt, __ap);
va_end(__ap);
// <20>ն<EFBFBD><D5B6><EFBFBD><EFBFBD><EFBFBD>
printf("[DEBUG] %s:%d => %s", file_name, line_no, __buf);
fflush(stdout);
// д<><D0B4> normalList
if (normalOutputEnabled) {
pthread_mutex_lock(&normalListMutex);
normalList.push_back(std::string(__buf));
pthread_mutex_unlock(&normalListMutex);
}
}
///////////////////////////////////////////////////////////////////////////////

View File

@@ -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