fix log realdata send funtion
This commit is contained in:
@@ -799,6 +799,21 @@ void rocketmq_test_rc()
|
||||
my_rocketmq_send(data);
|
||||
}
|
||||
|
||||
extern std::string G_MQCONSUMER_TOPIC_LOG;
|
||||
void rocketmq_test_log()
|
||||
{
|
||||
Ckafka_data_t data;
|
||||
data.monitor_id = 123123;
|
||||
data.strTopic = QString::fromStdString(G_MQCONSUMER_TOPIC_LOG);
|
||||
std::ifstream file("log_test.txt"); // 文件中存储长字符串
|
||||
std::stringstream buffer;
|
||||
buffer << file.rdbuf(); // 读取整个文件内容
|
||||
|
||||
data.strText = QString::fromStdString(buffer.str());
|
||||
data.mp_id = 123123;
|
||||
my_rocketmq_send(data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1043,6 +1043,7 @@ void init_config() {
|
||||
MULTIPLE_NODE_FLAG = 0;
|
||||
std::cout << "<EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:" << std::endl;
|
||||
}
|
||||
|
||||
//20250109lnk<6E><6B><EFBFBD>ӽ<EFBFBD><D3BD>̲<EFBFBD><CCB2>Դ<EFBFBD>ӡ<EFBFBD>˿<EFBFBD>
|
||||
if (g_node_id == STAT_DATA_BASE_NODE_ID)//ͳ<>Ʋɼ<C6B2>
|
||||
TEST_PORT = TEST_PORT + STAT_DATA_BASE_NODE_ID + g_front_seg_index;
|
||||
@@ -1055,7 +1056,7 @@ void init_config() {
|
||||
else if (g_node_id == SOE_COMTRADE_BASE_NODE_ID) {//<2F><>̬¼<CCAC><C2BC>
|
||||
TEST_PORT = TEST_PORT + SOE_COMTRADE_BASE_NODE_ID + g_front_seg_index;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// CZY <20><><EFBFBD><EFBFBD> ping IP
|
||||
@@ -3446,7 +3447,9 @@ int GetServerIndexFromDB() //
|
||||
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) >= 0) {
|
||||
ifc.ifc_len = sizeof buf;
|
||||
ifc.ifc_buf = (caddr_t)buf;
|
||||
|
||||
if (!ioctl(fd, SIOCGIFCONF, (char*)&ifc)) {
|
||||
|
||||
interface = ifc.ifc_len / sizeof(struct ifreq);
|
||||
printf("\ninterface num is interface= %d\n", interface);
|
||||
|
||||
@@ -15218,8 +15221,10 @@ void redirectWarnOutput(bool enabled) {
|
||||
if (enabled) {
|
||||
static RedirectStreamBuf warnBuf(warnList, warnListMutex);
|
||||
std::clog.rdbuf(&warnBuf);
|
||||
std::cerr.rdbuf(&warnBuf);
|
||||
} else {
|
||||
std::clog.rdbuf(nullptr); // <20>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>澯<EFBFBD><E6BEAF>
|
||||
std::cerr.rdbuf(nullptr); // <20>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15229,8 +15234,12 @@ void redirectNormalOutput(bool enabled) {
|
||||
if (enabled) {
|
||||
static RedirectStreamBuf normalBuf(normalList, normalListMutex);
|
||||
std::cout.rdbuf(&normalBuf);
|
||||
std::clog.rdbuf(&normalBuf);
|
||||
std::cerr.rdbuf(&normalBuf);
|
||||
} else {
|
||||
std::cout.rdbuf(nullptr); // <20>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
std::clog.rdbuf(nullptr); // <20>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>澯<EFBFBD><E6BEAF>
|
||||
std::cerr.rdbuf(nullptr); // <20>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15240,35 +15249,44 @@ int customPrintf(const char* format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
char buffer[1024];
|
||||
vsnprintf(buffer, sizeof(buffer), format, args);
|
||||
|
||||
// <20>ȸ<EFBFBD>ʽ<EFBFBD><CABD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD> buffer
|
||||
int written = vsnprintf(buffer, sizeof(buffer), format, args);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD>ԭʼ va_list
|
||||
va_end(args);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>п<EFBFBD><EFBFBD>ض<EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD>ԭ<EFBFBD><EFBFBD> printf <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (!errorOutputEnabled && !warnOutputEnabled && !normalOutputEnabled) {
|
||||
vprintf(format, args);
|
||||
return 0; // <20><><EFBFBD><EFBFBD>ֵΪ<D6B5>Ѵ<EFBFBD>ӡ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ش<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (written < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õĿ<C3B5><C4BF>ؽ<EFBFBD><D8BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD>б<EFBFBD><D0B1><EFBFBD>
|
||||
if (errorOutputEnabled) {
|
||||
pthread_mutex_lock(&errorListMutex); // <20><><EFBFBD><EFBFBD> errorList
|
||||
pthread_mutex_lock(&errorListMutex);
|
||||
errorList.push_back(buffer);
|
||||
pthread_mutex_unlock(&errorListMutex); // <20><><EFBFBD><EFBFBD> errorList
|
||||
pthread_mutex_unlock(&errorListMutex);
|
||||
}
|
||||
|
||||
if (warnOutputEnabled) {
|
||||
pthread_mutex_lock(&warnListMutex); // <20><><EFBFBD><EFBFBD> warnList
|
||||
pthread_mutex_lock(&warnListMutex);
|
||||
warnList.push_back(buffer);
|
||||
pthread_mutex_unlock(&warnListMutex); // <20><><EFBFBD><EFBFBD> warnList
|
||||
pthread_mutex_unlock(&warnListMutex);
|
||||
}
|
||||
|
||||
if (normalOutputEnabled) {
|
||||
pthread_mutex_lock(&normalListMutex); // <20><><EFBFBD><EFBFBD> normalList
|
||||
pthread_mutex_lock(&normalListMutex);
|
||||
normalList.push_back(buffer);
|
||||
pthread_mutex_unlock(&normalListMutex); // <20><><EFBFBD><EFBFBD> normalList
|
||||
pthread_mutex_unlock(&normalListMutex);
|
||||
}
|
||||
|
||||
return 0; // <20><><EFBFBD><EFBFBD>ֵΪ<EFBFBD>Ѵ<EFBFBD>ӡ<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>п<EFBFBD><EFBFBD>ض<EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD>ԭ<EFBFBD><EFBFBD> printf <20><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (!errorOutputEnabled && !warnOutputEnabled && !normalOutputEnabled) {
|
||||
// ֱ<><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ն<EFBFBD>
|
||||
std::cout << buffer << std::endl; // ʹ<><CAB9> std::cout <20><><EFBFBD><EFBFBD> printf <20><><EFBFBD>ij<EFBFBD>ͻ
|
||||
}
|
||||
|
||||
return written; // <20><><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD>ӡ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -4,9 +4,11 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
// 假设这些是你管理输出的列表
|
||||
extern std::list<std::string> errorList;
|
||||
extern std::list<std::string> warnList;
|
||||
@@ -17,8 +19,19 @@ extern bool errorOutputEnabled;
|
||||
extern bool warnOutputEnabled;
|
||||
extern bool normalOutputEnabled;
|
||||
|
||||
void redirectErrorOutput(bool enabled);
|
||||
void redirectWarnOutput(bool enabled);
|
||||
void redirectNormalOutput(bool enabled);
|
||||
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
// 自定义的 printf 函数
|
||||
int customPrintf(const char* format, ...);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
// 使用宏将 printf 替换为 customPrintf
|
||||
#define printf customPrintf
|
||||
|
||||
Reference in New Issue
Block a user