log optimize
This commit is contained in:
@@ -2890,11 +2890,11 @@ static void getDirectoryFilesInfo(const std::string &dirPath, std::vector<FileIn
|
||||
}
|
||||
|
||||
// 将 JSON 字符串写入指定文件
|
||||
// 注意此处仅做简单演示,实际项目中可加更多错误处理、日志输出等
|
||||
static void writeJsonToFile(const char* filePath, const char* jsonString)
|
||||
{
|
||||
FILE* fp = fopen(filePath, "w");
|
||||
if (!fp) {
|
||||
DIY_ERRORLOG("process","【ERROR】无法将暂态事件写入本地缓存");
|
||||
std::cerr << "Failed to write in file : " << filePath << std::endl;
|
||||
return;
|
||||
}
|
||||
@@ -2980,6 +2980,7 @@ static void scanAndResendOfflineFiles(const std::string &dirPath)
|
||||
// 读取文件内容(即之前存的 JSON)
|
||||
FILE* fp = fopen(fileList[i].fileName.c_str(), "r");
|
||||
if (!fp) {
|
||||
DIY_ERRORLOG("process","【ERROR】无法打开本地缓存的暂态事件");
|
||||
std::cerr << " fail to open exsist file " << fileList[i].fileName << std::endl;
|
||||
continue;
|
||||
}
|
||||
@@ -3127,7 +3128,7 @@ char* mp_id,char* Qvvr_rptname,char* devtype)
|
||||
std::cout << "qvvr send fail ,store in local" << std::endl;
|
||||
// 1) 先检查/FeProject/dat/qvvr/目录文件大小是否超过 10M,若超过则删除最老的一个文件
|
||||
std::string qvvrDir = "/FeProject/dat/qvvr/";
|
||||
checkAndRemoveOldestIfNeeded(qvvrDir, 10LL * 1024 * 1024);
|
||||
|
||||
|
||||
// 2) 将此条 json 存为文件,文件名: mp_id-start_time_str-dis_kind.txt
|
||||
// 例如: 502-2025-04-02 15:25:30.123-3.txt (仅示例)
|
||||
@@ -3144,6 +3145,8 @@ char* mp_id,char* Qvvr_rptname,char* devtype)
|
||||
|
||||
// 把 json_string 写入文件
|
||||
writeJsonToFile(fileName.c_str(), json_string);
|
||||
|
||||
checkAndRemoveOldestIfNeeded(qvvrDir, 10LL * 1024 * 1024);
|
||||
}
|
||||
else{
|
||||
free(j_r);
|
||||
@@ -3168,12 +3171,12 @@ char* mp_id,char* Qvvr_rptname,char* devtype)
|
||||
std::cout << "Error: Received NULL response" << std::endl;
|
||||
|
||||
//mq日志
|
||||
DIY_ERRORLOG(full_key_m_d,"【ERROR】暂态接口异常,无响应,无法上送监测点%s的暂态事件",mp_id);
|
||||
DIY_ERRORLOG(full_key_m_d,"【ERROR】暂态接口无响应,无法上送监测点%s的暂态事件",mp_id);
|
||||
|
||||
std::cout << "qvvr send fail ,store in local" << std::endl;
|
||||
// 1) 先检查/FeProject/dat/qvvr/目录文件大小是否超过 10M,若超过则删除最老的一个文件
|
||||
std::string qvvrDir = "/FeProject/dat/qvvr/";
|
||||
checkAndRemoveOldestIfNeeded(qvvrDir, 10LL * 1024 * 1024);
|
||||
|
||||
// 2) 将此条 json 存为文件,文件名: mp_id-start_time_str-dis_kind.txt
|
||||
// 例如: 502-2025-04-02 15:25:30.123-3.txt (仅示例)
|
||||
std::string fileName = qvvrDir;
|
||||
@@ -3189,6 +3192,8 @@ char* mp_id,char* Qvvr_rptname,char* devtype)
|
||||
// 把 json_string 写入文件
|
||||
writeJsonToFile(fileName.c_str(), json_string);
|
||||
|
||||
checkAndRemoveOldestIfNeeded(qvvrDir, 10LL * 1024 * 1024);
|
||||
|
||||
// 释放内存
|
||||
cJSON_Delete(root);
|
||||
free(json_string);
|
||||
|
||||
Reference in New Issue
Block a user