modify log format
This commit is contained in:
@@ -147,14 +147,14 @@ void handleUploadResponse(const std::string& response, std::string& wavepath) {
|
||||
}
|
||||
catch (const json::parse_error& e) {
|
||||
std::cerr << "Error parsing response: " << e.what() << std::endl;
|
||||
DIY_ERRORLOG("process", "【ERROR】前置上传暂态录波文件失败,web返回的消息不是json格式");
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_JSON, "前置上传文件失败,web响应异常");
|
||||
return;
|
||||
}
|
||||
|
||||
// 提取字段
|
||||
if (!json_data.contains("code") || !json_data.contains("data")) {
|
||||
std::cerr << "Error: Missing expected fields in JSON response." << std::endl;
|
||||
DIY_ERRORLOG("process", "【ERROR】前置上传暂态录波文件失败,web返回的消息没有远端文件名");
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_JSON, "前置上传文件失败,web响应异常");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ void handleUploadResponse(const std::string& response, std::string& wavepath) {
|
||||
auto& data = json_data["data"];
|
||||
if (!data.contains("name") || !data.contains("fileName") || !data.contains("url")) {
|
||||
std::cerr << "Error: Missing expected fields in JSON data object." << std::endl;
|
||||
DIY_ERRORLOG("process", "【ERROR】前置上传暂态录波文件失败,web返回的消息没有远端文件名");
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_JSON, "前置上传文件失败,web响应异常");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ void handleUploadResponse(const std::string& response, std::string& wavepath) {
|
||||
wavepath = nameWithoutExt;
|
||||
|
||||
std::cout << "wavepath: " << wavepath << std::endl;
|
||||
DIY_INFOLOG("process", "【NORMAL】前置上传暂态录波文件成功,远端文件名:%s", wavepath.c_str());
|
||||
DIY_INFOLOG("process", "前置上传暂态录波文件成功,远端文件名:%s", wavepath.c_str());
|
||||
}
|
||||
|
||||
//上传文件
|
||||
@@ -271,7 +271,7 @@ void SendFileWeb(const std::string& strUrl, const std::string& localpath, const
|
||||
if (res != CURLE_OK) {
|
||||
const char* em = errbuf[0] ? errbuf : curl_easy_strerror(res);
|
||||
std::cerr << "http web failed: " << em << std::endl;
|
||||
DIY_ERRORLOG("process","【ERROR】前置上传暂态录波文件 %s 失败,请检查文件上传接口配置",localpath.c_str());
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_CONFIG, "前置上传文件 %s 失败,请检查文件上传接口配置",localpath.c_str());
|
||||
} else {
|
||||
std::cout << "http web success, response: " << resPost0 << std::endl;
|
||||
handleUploadResponse(resPost0, wavepath); // 处理响应
|
||||
@@ -389,7 +389,7 @@ void download_xml_for_icd(const std::string& MODEL_ID,
|
||||
std::cout << "remote file name:" << remote_file_name << "local save name:" << save_name << std::endl;
|
||||
|
||||
// mq日志
|
||||
DIY_WARNLOG("process","【WARN】前置获取到终端类型%s,该终端类型对应的映射文件为%s,映射文件将下载并保存在本地为%s",TMNL_TYPE.c_str(),FILE_PATH.c_str(),save_name.c_str());
|
||||
|
||||
|
||||
std::string fileContent;
|
||||
std::string fullPath = std::string("filePath=") + filepath; //填写远端路径作为入参
|
||||
@@ -409,14 +409,14 @@ void download_xml_for_icd(const std::string& MODEL_ID,
|
||||
outFile.close();
|
||||
|
||||
std::cout << "File saved successfully!" << std::endl;
|
||||
DIY_WARNLOG("process","【WARN】前置下载映射文件%s成功",save_name.c_str());
|
||||
|
||||
} else {
|
||||
std::cerr << "Error: Unable to open file for writing." << std::endl;
|
||||
DIY_ERRORLOG("process","【ERROR】前置写入本地映射文件%s失败",save_name.c_str());
|
||||
|
||||
}
|
||||
} else {
|
||||
std::cerr << "Error: Unable to download file." << std::endl;
|
||||
DIY_ERRORLOG("process","【ERROR】前置调用文件下载接口下载远端文件文件%s失败",FILE_PATH.c_str());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -550,7 +550,7 @@ int terminal_ledger_web(std::map<std::string, terminal_dev>& terminal_dev_map,
|
||||
{
|
||||
if (inputstring.empty()) {
|
||||
std::cerr << "Error: inputstring is empty\n";
|
||||
DIY_ERRORLOG("process","【ERROR】前置的%d号进程调用web台账接口的入参为空", g_front_seg_index);
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_CONFIG,"台账接口的入参为空");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -569,7 +569,7 @@ int terminal_ledger_web(std::map<std::string, terminal_dev>& terminal_dev_map,
|
||||
break;
|
||||
}
|
||||
std::cerr << "data 无效或为空数组,重试\n";
|
||||
DIY_ERRORLOG("process","【ERROR】前置从web接口中获取的台账信息为空或者无效信息无法解析,请核对前置使用的入参信息:%s",inputparm.c_str());
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_JSON,"前置从web接口中获取的台账信息为空或者无效信息无法解析,请核对前置使用的入参信息:%s",inputparm.c_str());
|
||||
} catch (const nlohmann::json::parse_error& e) {
|
||||
std::cerr << "parse error: " << e.what() << ", retrying...\n";
|
||||
}
|
||||
@@ -586,7 +586,7 @@ int terminal_ledger_web(std::map<std::string, terminal_dev>& terminal_dev_map,
|
||||
if (json_data.contains("data") && json_data["data"].is_array() && !json_data["data"].empty()) {
|
||||
break;
|
||||
}
|
||||
DIY_ERRORLOG("process", "【ERROR】前置从本地台账中获取的台账信息为空或者无效信息无法解析,请核对前置使用的入参信息:%s",inputparm.c_str());
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_JSON, "前置从本地台账中获取的台账信息为空或者无效信息无法解析,请核对前置使用的入参信息:%s", inputparm.c_str());
|
||||
} catch (const nlohmann::json::parse_error& e) {
|
||||
std::cerr << "local parse error: " << e.what() << "\n";
|
||||
}
|
||||
@@ -709,7 +709,7 @@ int parse_device_cfg_web()
|
||||
input_jstr += "}";
|
||||
|
||||
std::cout << "input_jstr: " << input_jstr << std::endl;
|
||||
DIY_DEBUGLOG("process","【DEBUG】前置的%d号进程调用web接口获取台账使用的请求输入为:%s", g_front_seg_index, input_jstr.c_str());
|
||||
DIY_DEBUGLOG("process","前置获取台账使用的请求输入为:%s", input_jstr.c_str());
|
||||
|
||||
// 2. 调用接口
|
||||
std::map<std::string, terminal_dev> terminal_dev_map;
|
||||
@@ -738,10 +738,10 @@ int parse_device_cfg_web()
|
||||
|
||||
if (max_process_num != max_index) {
|
||||
if (max_process_num >= 1 && max_process_num <= 9) {
|
||||
DIY_WARNLOG("process", "【WARN】前置比对台账获取的进程数:%d和本地配置的进程数:%d,不匹配,按照台账进程数重置前置的进程数量",max_process_num, max_index);
|
||||
DIY_WARNLOG_CODE("process",0,LOG_CODE_CONFIG, "前置比对台账获取的进程数:%d和本地配置的进程数:%d,不匹配,按照台账进程数重置前置的进程数量",max_process_num, max_index);
|
||||
execute_bash("reset", max_process_num, "all");
|
||||
} else {
|
||||
DIY_ERRORLOG("process","【ERROR】前置从台账获取的进程数:%d不符合范围1~9,按照本地配置进程数启动进程",max_process_num);
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_CONFIG, "前置从台账获取的进程数:%d不符合范围1~9,按照本地配置进程数启动进程",max_process_num);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -749,13 +749,13 @@ int parse_device_cfg_web()
|
||||
// 5. 台账数量与配置比对
|
||||
int count_cfg = static_cast<int>(terminal_dev_map.size());
|
||||
std::cout << "terminal_ledger_num: " << count_cfg << std::endl;
|
||||
DIY_DEBUGLOG("process", "【DEBUG】前置的%d号进程调用获取到的台账的数量为:%d", g_front_seg_index, count_cfg);
|
||||
DIY_DEBUGLOG("process", "前置获取到的台账的数量为:%d",count_cfg);
|
||||
|
||||
if (IED_COUNT < count_cfg) {
|
||||
std::cout << "!!!!!!!!!!single process has ledger count more than config!!!!!!!" << std::endl;
|
||||
//DIY_WARNLOG("process","【WARN】前置的%d号进程获取到的台账的数量大于配置文件中给单个进程配置的台账数量:%d,这个进程将按照获取到的台账的数量来创建台账空间,这个进程不能直接通过台账添加来新增台账,只能通过重启进程或者先删除已有台账再添加台账的方式来添加新台账", g_front_seg_index, IED_COUNT);
|
||||
|
||||
} else {
|
||||
//DIY_INFOLOG("process","【NORMAL】前置的%d号进程根据配置文件中给单个进程配置的台账数量:%d来创建台账空间", g_front_seg_index, IED_COUNT);
|
||||
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////用例这里将局部的map拷贝到全局map,后续根据协议台账修改
|
||||
@@ -807,7 +807,7 @@ int parse_device_cfg_web()
|
||||
if (!mon.terminal_connect.empty() && mon.terminal_connect != "0") {
|
||||
isdelta_flag = 1;
|
||||
std::cout << "monitor_id " << mon.monitor_id<< " v_wiring_type: " << mon.terminal_connect << " is delta wiring: " << isdelta_flag << std::endl;
|
||||
DIY_WARNLOG("process","【WARN】前置连接的监测点%s是角形接线,对应终端为%s 终端类型是%s",mon.monitor_id.c_str(),dev.terminal_id.c_str(),dev.dev_type.c_str());
|
||||
DIY_WARNLOG_CODE("process",0,LOG_CODE_WIRETYPE,"装置:%s - 监测点: %s 是角形接线",dev.terminal_name.c_str(),mon.monitor_name.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -938,7 +938,7 @@ int parse_model_cfg_web()
|
||||
// 3. 调用接口
|
||||
std::map<std::string, icd_model*> icd_model_map;
|
||||
if (parse_model_web(&icd_model_map, input_jstr)) {
|
||||
DIY_ERRORLOG("process", "【ERROR】前置的%d号进程 icd模型接口异常,将使用默认的icd模型,请检查接口配置", g_front_seg_index);
|
||||
|
||||
// 确保释放 map
|
||||
for (auto& kv : icd_model_map) delete kv.second;
|
||||
return 0;
|
||||
@@ -992,7 +992,7 @@ std::string parse_model_cfg_web_one(const std::string& terminal_type)
|
||||
// 2. 拉取并解析
|
||||
if (parse_model_web(&icd_model_map, input_jstr) != 0) {
|
||||
std::cerr << "parse_model_web failed for type: " << terminal_type << std::endl;
|
||||
DIY_ERRORLOG("process","【ERROR】前置的%d号进程 icd模型接口异常,将使用默认的icd模型,请检查接口配置", g_front_seg_index);
|
||||
|
||||
// 清理(即使 map 为空,也安全)
|
||||
for (auto& kv : icd_model_map) delete kv.second;
|
||||
return "";
|
||||
@@ -1054,7 +1054,7 @@ static void writeJsonToFile(const std::string& filePath, const std::string& json
|
||||
{
|
||||
FILE* fp = fopen(filePath.c_str(), "w");
|
||||
if (!fp) {
|
||||
DIY_ERRORLOG("process", "【ERROR】无法将暂态事件写入本地缓存");
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_TRANSIENT_COMM, "前置无法将暂态事件写入本地缓存");
|
||||
std::cerr << "Failed to write in file : " << filePath << std::endl;
|
||||
return;
|
||||
}
|
||||
@@ -1166,7 +1166,7 @@ static void scanAndResendOfflineFiles(const std::string& dirPath)
|
||||
// 读取 JSON 文件内容
|
||||
std::ifstream inFile(file.fileName.c_str());
|
||||
if (!inFile) {
|
||||
DIY_ERRORLOG("process", "【ERROR】无法打开本地缓存的暂态事件");
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_TRANSIENT_COMM, "无法打开本地缓存的暂态事件");
|
||||
std::cerr << "fail to open existing file: " << file.fileName << std::endl;
|
||||
continue;
|
||||
}
|
||||
@@ -1185,14 +1185,14 @@ static void scanAndResendOfflineFiles(const std::string& dirPath)
|
||||
try {
|
||||
json j_r = json::parse(response);
|
||||
|
||||
DIY_WARNLOG("process", "【WARN】前置重发暂态事件成功");
|
||||
DIY_WARNLOG_CODE("process",0,LOG_CODE_TRANSIENT_COMM, "前置重发暂态事件成功");
|
||||
std::cout << "old file send success, remove it" << std::endl;
|
||||
|
||||
std::remove(file.fileName.c_str());
|
||||
} catch (...) {
|
||||
std::cout << "old file send fail (response parse failed)" << std::endl;
|
||||
|
||||
DIY_WARNLOG("process", "【WARN】前置重发暂态事件失败");
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_TRANSIENT_COMM, "前置重发暂态事件失败");
|
||||
handleCommentResponse(response); // 仍然处理文本响应
|
||||
}
|
||||
} else {
|
||||
@@ -1230,12 +1230,21 @@ int transfer_json_qvvr_data(const std::string& dev_id, ushort monitor_id,
|
||||
//找监测点id
|
||||
std::string mpid;
|
||||
|
||||
//找测点名称
|
||||
std::string mpname;
|
||||
|
||||
//找装置名称
|
||||
std::string devname;
|
||||
|
||||
get_monitor_id_by_dev_and_seq(dev_id, monitor_id, mpid);
|
||||
if(mpid.empty()) {
|
||||
std::cout << "qvvr send error ,monitorId is null" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
get_terminal_name_by_terminal_id(dev_id, devname);
|
||||
get_monitor_name_by_monitor_id(mpid, mpname);
|
||||
|
||||
root["monitorId"] = mpid;
|
||||
root["devId"] = dev_id;
|
||||
root["CpuNo"] = monitor_id;
|
||||
@@ -1279,7 +1288,7 @@ int transfer_json_qvvr_data(const std::string& dev_id, ushort monitor_id,
|
||||
// 有效响应,略过
|
||||
} catch (...) {
|
||||
// 响应异常,保存 json
|
||||
DIY_ERRORLOG(mpid.c_str(), "【ERROR】暂态接口响应异常,无法上送装置%s监测点%u的暂态事件",dev_id.c_str(), (unsigned)monitor_id);
|
||||
DIY_ERRORLOG_CODE(mpid.c_str(),2,LOG_CODE_TRANSIENT_COMM, "暂态接口响应异常,无法上送装置%s - 监测点%s的暂态事件",devname.c_str(), mpname.c_str());
|
||||
|
||||
std::cout << "qvvr send fail ,store in local" << std::endl;
|
||||
std::string qvvrDir = FRONT_PATH + "/dat/qvvr/";
|
||||
@@ -1289,7 +1298,7 @@ int transfer_json_qvvr_data(const std::string& dev_id, ushort monitor_id,
|
||||
}
|
||||
} else {
|
||||
// 无响应,保存 json
|
||||
DIY_ERRORLOG(mpid.c_str(), "【ERROR】暂态接口无响应,无法上送装置%s监测点%u的暂态事件",dev_id.c_str(), (unsigned)monitor_id);
|
||||
DIY_ERRORLOG_CODE(mpid.c_str(),2,LOG_CODE_TRANSIENT_COMM,"暂态接口无响应,无法上送装置%s - 监测点%s的暂态事件",devname.c_str(), mpname.c_str());
|
||||
|
||||
std::cout << "qvvr send fail ,store in local" << std::endl;
|
||||
std::string qvvrDir = FRONT_PATH + "/dat/qvvr/";
|
||||
@@ -1385,5 +1394,33 @@ bool get_monitor_id_by_dev_and_seq(const std::string& terminal_id,
|
||||
return false;
|
||||
}
|
||||
|
||||
// 根据 monitor_id 查 monitor_name
|
||||
bool get_monitor_name_by_monitor_id(const std::string& monitor_id,
|
||||
std::string& out_monitor_name)
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(ledgermtx);
|
||||
|
||||
for (const auto& dev : terminal_devlist) {
|
||||
for (const auto& mon : dev.line) {
|
||||
if (mon.monitor_id == monitor_id) {
|
||||
out_monitor_name = mon.monitor_name;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool get_terminal_name_by_terminal_id(const std::string& terminal_id,
|
||||
std::string& out_terminal_name)
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(ledgermtx);
|
||||
|
||||
for (const auto& dev : terminal_devlist) {
|
||||
if (dev.terminal_id == terminal_id) {
|
||||
out_terminal_name = dev.terminal_name;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user