add log realdata send funtion

This commit is contained in:
lnk
2025-02-25 16:33:11 +08:00
parent d1fa47e3f1
commit c597ee5b9b
5 changed files with 345 additions and 4 deletions

View File

@@ -312,6 +312,12 @@ std::string G_MQCONSUMER_KEY_RC = "";//consumer key
std::string G_MQCONSUMER_TOPIC_SET = "";//consumer topie
std::string G_MQCONSUMER_TAG_SET = "";//consumer tag
std::string G_MQCONSUMER_KEY_SET = "";//consumer key
std::string G_LOG_TOPIC = "";//topie
std::string G_LOG_TAG = "";//tag
std::string G_LOG_KEY = "";//key
std::string G_MQCONSUMER_TOPIC_LOG = "";//consumer topie
std::string G_MQCONSUMER_TAG_LOG = "";//consumer tag
std::string G_MQCONSUMER_KEY_LOG = "";//consumer key
int G_TEST_FLAG = 0;
int G_TEST_NUM = 0;
@@ -896,6 +902,19 @@ void init_config() {
G_MQCONSUMER_TAG_SET = strdup(ba.data());
ba = settings.value("RocketMq/ConsumerKeySET", "").toString().toLatin1();
G_MQCONSUMER_KEY_SET = strdup(ba.data());
ba = settings.value("RocketMq/ConsumerTopicLOG", "").toString().toLatin1();
G_MQCONSUMER_TOPIC_LOG = strdup(ba.data());
ba = settings.value("RocketMq/ConsumerTagLOG", "").toString().toLatin1();
G_MQCONSUMER_TAG_LOG = strdup(ba.data());
ba = settings.value("RocketMq/ConsumerKeyLOG", "").toString().toLatin1();
G_MQCONSUMER_KEY_LOG = strdup(ba.data());
ba = settings.value("RocketMq/LOGTopic", "").toString().toLatin1();
G_LOG_TOPIC = strdup(ba.data());
ba = settings.value("RocketMq/LOGTag", "").toString().toLatin1();
G_LOG_TAG = strdup(ba.data());
ba = settings.value("RocketMq/LOGKey", "").toString().toLatin1();
G_LOG_KEY = strdup(ba.data());
//MQ<4D><51><EFBFBD><EFBFBD>
G_TEST_FLAG = settings.value("RocketMq/Testflag", 0).toInt();
G_TEST_NUM = settings.value("RocketMq/Testnum", 0).toInt();
@@ -909,6 +928,9 @@ void init_config() {
std::cout << "Read G_ROCKETMQ_TAG:" << G_ROCKETMQ_TAG << std::endl;
std::cout << "Read G_ROCKETMQ_KEY:" << G_ROCKETMQ_KEY << std::endl;
std::cout << "Read QUEUENUM:" << QUEUENUM << std::endl;
std::cout << "Read G_LOG_TOPIC:" << G_LOG_TOPIC << std::endl;
std::cout << "Read G_LOG_TAG:" << G_LOG_TAG << std::endl;
std::cout << "Read G_LOG_KEY:" << G_LOG_KEY << std::endl;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ش<EFBFBD>ӡ
std::cout << "Read G_ROCKETMQ_CONSUMER:" << G_ROCKETMQ_CONSUMER << std::endl;
std::cout << "Read G_MQCONSUMER_IPPORT:" << G_MQCONSUMER_IPPORT << std::endl;
@@ -927,6 +949,9 @@ void init_config() {
std::cout << "Read G_MQCONSUMER_TOPIC_SET:" << G_MQCONSUMER_TOPIC_SET << std::endl;
std::cout << "Read G_MQCONSUMER_TAG_SET:" << G_MQCONSUMER_TAG_SET << std::endl;
std::cout << "Read G_MQCONSUMER_KEY_SET:" << G_MQCONSUMER_KEY_SET << std::endl;
std::cout << "Read G_MQCONSUMER_TOPIC_LOG:" << G_MQCONSUMER_TOPIC_LOG << std::endl;
std::cout << "Read G_MQCONSUMER_TAG_LOG:" << G_MQCONSUMER_TAG_LOG << std::endl;
std::cout << "Read G_MQCONSUMER_KEY_LOG:" << G_MQCONSUMER_KEY_LOG << std::endl;
//Mq<4D><71><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ش<EFBFBD>ӡ
std::cout << "Read G_TEST_FLAG:" << G_TEST_FLAG << std::endl;
std::cout << "Read G_TEST_NUM:" << G_TEST_NUM << std::endl;
@@ -15137,6 +15162,115 @@ void rocketmq_test_300(int mpnum,int front_index) {
std::cout << "Finished sending " << total_messages << " messages." << std::endl;
}
///////////////////////////////////////////////////////////////////////////////lnkʵʱ<CAB5><CAB1>־<EFBFBD><D6BE><EFBFBD><EFBFBD>20250205
// ȫ<><C8AB><EFBFBD>б<EFBFBD><D0B1>Ϳ<EFBFBD><CDBF><EFBFBD>
std::list<std::string> errorList;
std::list<std::string> warnList;
std::list<std::string> normalList;
// <20><><EFBFBD><EFBFBD>ȫ<EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD><EFBFBD>
pthread_mutex_t errorListMutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t warnListMutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t normalListMutex = PTHREAD_MUTEX_INITIALIZER;
bool errorOutputEnabled = false;
bool warnOutputEnabled = false;
bool normalOutputEnabled = false;
// <20>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
class RedirectStreamBuf : public std::streambuf {
public:
RedirectStreamBuf(std::list<std::string>& targetList, pthread_mutex_t& targetMutex)
: targetList(targetList), targetMutex(targetMutex) {}
protected:
virtual int_type overflow(int_type ch) override {
if (ch != EOF) {
char c = static_cast<char>(ch);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> targetList
pthread_mutex_lock(&targetMutex);
targetList.push_back(std::string(1, c));
pthread_mutex_unlock(&targetMutex);
}
return ch;
}
private:
std::list<std::string>& targetList;
pthread_mutex_t& targetMutex;
};
// <20>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void redirectErrorOutput(bool enabled) {
errorOutputEnabled = enabled;
if (enabled) {
static RedirectStreamBuf errorBuf(errorList, errorListMutex);
std::cerr.rdbuf(&errorBuf);
} else {
std::cerr.rdbuf(nullptr); // <20>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>׼<EFBFBD><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
}
// <20>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><E6BEAF><EFBFBD><EFBFBD>
void redirectWarnOutput(bool enabled) {
warnOutputEnabled = enabled;
if (enabled) {
static RedirectStreamBuf warnBuf(warnList, warnListMutex);
std::clog.rdbuf(&warnBuf);
} else {
std::clog.rdbuf(nullptr); // <20>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>׼<EFBFBD><EFBFBD><E6BEAF>
}
}
// <20>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD>
void redirectNormalOutput(bool enabled) {
normalOutputEnabled = enabled;
if (enabled) {
static RedirectStreamBuf normalBuf(normalList, normalListMutex);
std::cout.rdbuf(&normalBuf);
} else {
std::cout.rdbuf(nullptr); // <20>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>׼<EFBFBD><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
}
// <20>Զ<EFBFBD><D4B6><EFBFBD> printf <20><><EFBFBD><EFBFBD>
int customPrintf(const char* format, ...) {
va_list args;
va_start(args, format);
char buffer[1024];
vsnprintf(buffer, sizeof(buffer), format, args);
va_end(args);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>п<EFBFBD><D0BF>ض<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>ԭ<EFBFBD><D4AD> printf <20><><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>õĿ<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
errorList.push_back(buffer);
pthread_mutex_unlock(&errorListMutex); // <20><><EFBFBD><EFBFBD> errorList
}
if (warnOutputEnabled) {
pthread_mutex_lock(&warnListMutex); // <20><><EFBFBD><EFBFBD> warnList
warnList.push_back(buffer);
pthread_mutex_unlock(&warnListMutex); // <20><><EFBFBD><EFBFBD> warnList
}
if (normalOutputEnabled) {
pthread_mutex_lock(&normalListMutex); // <20><><EFBFBD><EFBFBD> normalList
normalList.push_back(buffer);
pthread_mutex_unlock(&normalListMutex); // <20><><EFBFBD><EFBFBD> normalList
}
return 0; // <20><><EFBFBD><EFBFBD>ֵΪ<D6B5>Ѵ<EFBFBD>ӡ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
}
///////////////////////////////////////////////////////////////////////////////

26
cfg_parse/custom_printf.h Normal file
View File

@@ -0,0 +1,26 @@
// custom_printf.h
#ifndef CUSTOM_PRINTF_H
#define CUSTOM_PRINTF_H
#include <stdio.h>
#include <stdarg.h>
#include <list>
#include <string>
// 假设这些是你管理输出的列表
extern std::list<std::string> errorList;
extern std::list<std::string> warnList;
extern std::list<std::string> normalList;
// 开关
extern bool errorOutputEnabled;
extern bool warnOutputEnabled;
extern bool normalOutputEnabled;
// 自定义的 printf 函数
int customPrintf(const char* format, ...);
// 使用宏将 printf 替换为 customPrintf
#define printf customPrintf
#endif // CUSTOM_PRINTF_H