modify log
This commit is contained in:
@@ -566,7 +566,7 @@ void init_config() {
|
||||
std::cout << "this is multiple process of index:" << g_front_seg_index << std::endl;
|
||||
|
||||
if(g_front_seg_index > g_front_seg_num){
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_CONFIG,"进程号应该为1到配置的最大进程号范围内的整数,退出当前进程");
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_CONFIG,"进程号参数异常,当前进程退出");
|
||||
exit(-1039);
|
||||
}
|
||||
|
||||
@@ -576,22 +576,10 @@ void init_config() {
|
||||
std::cout << "this is single process" << std::endl;
|
||||
}
|
||||
else{
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_CONFIG,"进程号应该为1到配置的最大进程号范围内的整数,退出当前进程");
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_CONFIG,"进程号参数异常,当前进程退出");
|
||||
exit(-1039);
|
||||
}
|
||||
|
||||
//测试进程端口
|
||||
/*if (g_node_id == STAT_DATA_BASE_NODE_ID)//统计采集
|
||||
TEST_PORT = TEST_PORT + STAT_DATA_BASE_NODE_ID + g_front_seg_index;
|
||||
else if (g_node_id == RECALL_HIS_DATA_BASE_NODE_ID) {//补召
|
||||
TEST_PORT = TEST_PORT + RECALL_HIS_DATA_BASE_NODE_ID + g_front_seg_index;
|
||||
}
|
||||
else if (g_node_id == THREE_SECS_DATA_BASE_NODE_ID) {//3秒采集
|
||||
TEST_PORT = TEST_PORT + THREE_SECS_DATA_BASE_NODE_ID + g_front_seg_index;
|
||||
}
|
||||
else if (g_node_id == SOE_COMTRADE_BASE_NODE_ID) {//暂态录波
|
||||
TEST_PORT = TEST_PORT + SOE_COMTRADE_BASE_NODE_ID + g_front_seg_index;
|
||||
}*/
|
||||
//测试端口处理
|
||||
TEST_PORT = TEST_PORT + g_front_seg_index;
|
||||
}
|
||||
|
||||
@@ -1232,23 +1220,20 @@ int recall_json_handle_from_mq(const std::string& body)
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "Error parsing JSON: " << e.what() << std::endl;
|
||||
// ★与原逻辑等价:无法解析,不再进入 recall_json_handle
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_JSON,"主题:%s - tag:%s的补招触发消息失败",
|
||||
G_MQCONSUMER_TOPIC_RC.c_str(), FRONT_INST.c_str());
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_JSON,"无法解析补招信息,补招触发失败");
|
||||
return 10004;
|
||||
}
|
||||
|
||||
// 提取 "messageBody"(字符串)
|
||||
if (!root.contains("messageBody") || !root["messageBody"].is_string()) {
|
||||
std::cerr << "'messageBody' is missing or is not a string" << std::endl;
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_JSON,"主题:%s - tag:%s的补招触发消息失败",
|
||||
G_MQCONSUMER_TOPIC_RC.c_str(), FRONT_INST.c_str());
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_JSON,"无法解析补招信息,补招触发失败");
|
||||
return 10004;
|
||||
}
|
||||
std::string messageBodyStr = root["messageBody"].get<std::string>();
|
||||
if (messageBodyStr.empty()) {
|
||||
std::cerr << "'messageBody' is empty" << std::endl;
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_JSON,"主题:%s - tag:%s的补招触发消息失败",
|
||||
G_MQCONSUMER_TOPIC_RC.c_str(), FRONT_INST.c_str());
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_JSON,"无法解析补招信息,补招触发失败");
|
||||
return 10004;
|
||||
}
|
||||
|
||||
@@ -1258,8 +1243,7 @@ int recall_json_handle_from_mq(const std::string& body)
|
||||
mb = nlohmann::json::parse(messageBodyStr);
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "Failed to parse 'messageBody' JSON: " << e.what() << std::endl;
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_JSON,"主题:%s - tag:%s的补招触发消息失败",
|
||||
G_MQCONSUMER_TOPIC_RC.c_str(), FRONT_INST.c_str());
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_JSON,"无法解析补招信息,补招触发失败");
|
||||
return 10004;
|
||||
}
|
||||
|
||||
|
||||
@@ -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_CODE("process",0,LOG_CODE_JSON, "前置上传文件失败,web响应异常");
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_JSON, "文件上传接口响应异常,上传文件失败");
|
||||
return;
|
||||
}
|
||||
|
||||
// 提取字段
|
||||
if (!json_data.contains("code") || !json_data.contains("data")) {
|
||||
std::cerr << "Error: Missing expected fields in JSON response." << std::endl;
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_JSON, "前置上传文件失败,web响应异常");
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_JSON, "文件上传接口响应异常,上传文件失败");
|
||||
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_CODE("process",0,LOG_CODE_JSON, "前置上传文件失败,web响应异常");
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_JSON, "文件上传接口响应异常,上传文件失败");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -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_CODE("process",0,LOG_CODE_CONFIG, "前置上传文件 %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); // 处理响应
|
||||
@@ -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_CODE("process",0,LOG_CODE_CONFIG,"台账接口的入参为空");
|
||||
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_CODE("process",0,LOG_CODE_JSON,"前置从web接口中获取的台账信息为空或者无效信息无法解析,请核对接口参数和前置使用的入参信息:%s",inputparm.c_str());
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_JSON,"从台账接口中获取到的台账信息为无效信息,台账初始化失败");
|
||||
} catch (const nlohmann::json::parse_error& e) {
|
||||
std::cerr << "parse error: " << e.what() << ", retrying...\n";
|
||||
}
|
||||
@@ -579,7 +579,7 @@ int terminal_ledger_web(std::map<std::string, terminal_dev>& terminal_dev_map,
|
||||
|
||||
if (++retry > 3) {
|
||||
std::cerr << "web error after 3 retry, fallback to local file\n";
|
||||
DIY_WARNLOG_CODE("process",0,LOG_CODE_CONFIG, "前置无法从接口获取台账,从本地读取上一次缓存的台账,请核对接口参数和前置使用的入参信息:%s", inputparm.c_str());
|
||||
DIY_WARNLOG_CODE("process",0,LOG_CODE_CONFIG, "无法从台账接口获取台账,将从本地读取上一次缓存的台账");
|
||||
std::string ledger = read_latest_ledger_file();
|
||||
if (!ledger.empty()) {
|
||||
try {
|
||||
@@ -587,7 +587,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_CODE("process",0,LOG_CODE_JSON, "前置从本地台账中获取的台账信息为空或者无效信息无法解析,请核对接口参数和前置使用的入参信息:%s", inputparm.c_str());
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_JSON,"从本地台账中获取到的台账信息为无效信息,台账初始化失败");
|
||||
} catch (const nlohmann::json::parse_error& e) {
|
||||
std::cerr << "local parse error: " << e.what() << "\n";
|
||||
}
|
||||
@@ -739,10 +739,10 @@ int parse_device_cfg_web()
|
||||
|
||||
if (max_process_num != max_index) {
|
||||
if (max_process_num >= 1 && max_process_num <= 9) {
|
||||
DIY_WARNLOG_CODE("process",0,LOG_CODE_CONFIG, "前置比对台账获取的进程数:%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_CODE("process",0,LOG_CODE_CONFIG, "前置从台账获取的进程数:%d不符合范围1~9,按照本地配置进程数启动进程",max_process_num);
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_CONFIG, "从台账获取到的总进程数:%d不符合范围1~9,不会重置进程",max_process_num);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1289,7 +1289,33 @@ int transfer_json_qvvr_data(const std::string& dev_id, ushort monitor_id,
|
||||
if (!response.empty()) {
|
||||
try {
|
||||
json j_r = json::parse(response);
|
||||
// 有效响应,略过
|
||||
// =====【新增:业务失败也当异常处理】=====
|
||||
if (j_r.contains("code")
|
||||
&& j_r["code"].is_string()
|
||||
&& j_r["code"].get<std::string>() != "0") {
|
||||
|
||||
DIY_ERRORLOG_CODE(
|
||||
mpid.c_str(),
|
||||
2,
|
||||
LOG_CODE_TRANSIENT_COMM,
|
||||
"暂态接口业务失败(code=%s),无法上送装置%s - 监测点%s的暂态事件",
|
||||
j_r["code"].get<std::string>().c_str(),
|
||||
showName_d,
|
||||
showName_m
|
||||
);
|
||||
|
||||
std::cout << "qvvr send fail ,store in local" << std::endl;
|
||||
std::string qvvrDir = FRONT_PATH + "/dat/qvvr/";
|
||||
std::string fileName = qvvrDir + dev_id + "-" +
|
||||
std::to_string(monitor_id) + "-" +
|
||||
FormatTimeForFilename(start_time_str) + "-" +
|
||||
std::to_string(dis_kind) + ".txt";
|
||||
|
||||
writeJsonToFile(fileName, json_string);
|
||||
checkAndRemoveOldestIfNeeded(qvvrDir, 10LL * 1024 * 1024);
|
||||
}
|
||||
// =====【新增结束】=====
|
||||
|
||||
} catch (...) {
|
||||
// 响应异常,保存 json
|
||||
DIY_ERRORLOG_CODE(mpid.c_str(),2,LOG_CODE_TRANSIENT_COMM, "暂态接口响应异常,无法上送装置%s - 监测点%s的暂态事件",showName_d, showName_m);
|
||||
|
||||
@@ -238,7 +238,7 @@ private:
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
// 前 5 次:1 秒一次;第 6 次起:300 秒一次
|
||||
// 前 3 次:1 秒一次;第 3 次起:300 秒一次,一小时恢复
|
||||
static bool should_emit(const std::string& key) {
|
||||
using namespace std::chrono;
|
||||
const auto now = steady_clock::now();
|
||||
|
||||
@@ -680,7 +680,7 @@ bool parseJsonMessageLOG(const std::string& json_str) {
|
||||
process_log_command(id, level, grade, logtype);
|
||||
} else {
|
||||
std::cout << "type doesn't match" << std::endl;
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_JSON, "日志控制指令失败");
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_JSON, "无法解析日志控制指令,日志控制失败");
|
||||
}
|
||||
|
||||
std::cout << "this msg should only execute once" << std::endl;
|
||||
@@ -1047,7 +1047,7 @@ rocketmq::ConsumeStatus myMessageCallbackrtdata(const rocketmq::MQMessageExt& ms
|
||||
|
||||
if (!parseJsonMessageRT(body, devid, line, realData, soeData, limit,idx)) {
|
||||
std::cerr << "Failed to parse the JSON message." << std::endl;
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_JSON, "主题:%s - tag:%s的实时触发消息失败", G_MQCONSUMER_TOPIC_RT.c_str(), FRONT_INST.c_str());
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_JSON, "无法解析实时数据触发消息,实时数据触发失败");
|
||||
return rocketmq::RECONSUME_LATER;
|
||||
}
|
||||
|
||||
@@ -1080,7 +1080,7 @@ rocketmq::ConsumeStatus myMessageCallbackrtdata(const rocketmq::MQMessageExt& ms
|
||||
if (ClientManager::instance().get_dev_status(devid) != 1) {
|
||||
std::cout << "devid对应装置不在线: " << devid << std::endl;
|
||||
// 记录日志不响应 web 端
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_COMM,"主题:%s - tag:%s的实时数据触发消息失败,装置:%s 不在线", G_MQCONSUMER_TOPIC_RT.c_str(),FRONT_INST.c_str(),showName);
|
||||
DIY_WARNLOG_CODE(devid,1,LOG_CODE_COMM,"装置不在线,实时数据触发失败");
|
||||
return rocketmq::CONSUME_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1091,7 +1091,7 @@ rocketmq::ConsumeStatus myMessageCallbackrtdata(const rocketmq::MQMessageExt& ms
|
||||
}
|
||||
else{
|
||||
std::cerr << "rtdata is NULL." << std::endl;
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_JSON,"主题:%s - tag:%s的补招触发消息失败",G_MQCONSUMER_TOPIC_RT.c_str(),FRONT_INST.c_str());
|
||||
DIY_ERRORLOG_CODE("process",0,LOG_CODE_JSON, "无法解析实时数据触发消息,实时数据触发失败");
|
||||
return rocketmq::RECONSUME_LATER;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user