baseEx.cpp 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616
  1. #include "stdafx.h"
  2. #include "baseEx.h"
  3. #include <stdint.h>
  4. #include <iostream>
  5. #include <vector>
  6. #include <map>
  7. #include <boost/xpressive/xpressive_dynamic.hpp>
  8. #include <boost/algorithm/string.hpp>
  9. #include <boost/filesystem.hpp>
  10. #include <boost/chrono.hpp>
  11. #include <boost/interprocess/ipc/message_queue.hpp>
  12. #include <boost/interprocess/permissions.hpp>
  13. #include <boost/thread/mutex.hpp>
  14. #include <boost/thread/lock_guard.hpp>
  15. #include <boost/algorithm/hex.hpp>
  16. #include "winpr/sysinfo.h"
  17. #include "winpr/timezone.h"
  18. #include "EventCode.h"
  19. #include "exLog/log.h"
  20. #include "cJSON.h"
  21. #include "RVCComm.h"
  22. #include "CommEntityUtil.hpp"
  23. using namespace boost::interprocess;
  24. //read ini
  25. #include <boost/property_tree/ptree.hpp>
  26. #include <boost/property_tree/ini_parser.hpp>
  27. #if (defined _WIN32 || defined _WIN64)
  28. #include <ShellAPI.h>
  29. #define BOOST_INTERPROCESS_SHARED_DIR_PATH "C:\\"
  30. #else
  31. #include <sys/types.h>
  32. #include <unistd.h>
  33. #include <cstring>
  34. #include <signal.h>
  35. #endif
  36. std::string g_usercodeTranslateFile = "";
  37. std::map<std::string, std::vector<std::string>> g_networkParse;
  38. std::map<std::string, clock_t> g_networkExpiredData;
  39. std::map<std::string, ErrMsgStruct> g_UserCodeToMsgTip;
  40. boost::mutex g_networkMutex;
  41. const std::wstring WCHAR_NULL = L"";
  42. const std::wstring specialStr = L"乗俓僜刓匼哱圽塡奬媆峔嶾廫慭怽揬昞朶梊榎橽歕沑漒瀄焅燶猏玕琝甛璡痋盶癨瞈砛碶穃竆筡篭糪絓綷縗繺羂耚肻腬臶臷芢蒤薥蚛蝄蟎衆蟎裓覾譢豛赲踈躙輁郳醆鈂鉢鎈鏫閈闬隲頫颸餦馶骪鯸鮘鳿鵟鸤黒齖";
  43. #define NOR_LEN 50
  44. #define MAX_LOG_LEN 4096
  45. #define MAX_CEFLOG_LEN 5120
  46. std::string UtfToGbk(const char* utf8)
  47. {
  48. #if (defined _WIN32 || defined _WIN64)
  49. std::string val(utf8);
  50. SP::Module::Util::ConvertUtf82GBK(val);
  51. return val;
  52. #else
  53. return utf8;
  54. #endif
  55. }
  56. struct cefclientLog {
  57. LOG_LEVEL_E m_level;
  58. LOG_TYPE_E m_type;
  59. char m_logTime[NOR_LEN];
  60. char m_filename[NOR_LEN];
  61. int m_filePos;
  62. char m_cefLog[MAX_CEFLOG_LEN];
  63. cefclientLog(LOG_LEVEL_E t_level, LOG_TYPE_E t_type, const char* t_logTime, const char* t_filename, int t_filePos, const char* t_cefLog) {
  64. m_level = t_level;
  65. m_type = t_type;
  66. strcpy_s(m_logTime, NOR_LEN, t_logTime);
  67. strcpy_s(m_filename, NOR_LEN, t_filename);
  68. m_filePos = t_filePos;
  69. strcpy_s(m_cefLog, MAX_CEFLOG_LEN, t_cefLog);
  70. }
  71. cefclientLog()
  72. :m_level(LOG_LEVEL_DEBUG), m_type(LOG_TYPE_SYSTEM), m_filePos(0)
  73. {
  74. memset(m_logTime, 0, NOR_LEN);
  75. memset(m_filename, 0, NOR_LEN);
  76. memset(m_cefLog, 0, MAX_CEFLOG_LEN);
  77. }
  78. };
  79. #define CEF_GUID "{5ED197CD-9D64-4D10-9839-2A0773B6F5D2}"
  80. bool InitFileLogger(std::string dbgPath)
  81. {
  82. auto ret = logger::init(dbgPath.c_str(), "cefLog");
  83. ConfigManager::getInstance().setLoggerInitSuccess(ret);
  84. return ret;
  85. }
  86. void DbgToFileLogger(std::string msg)
  87. {
  88. if(ConfigManager::getInstance().isLoggerInitSuccess())
  89. logger::showLog(msg);
  90. }
  91. void DbgEx(const char* str, ...)
  92. {
  93. va_list arg;
  94. va_start(arg, str);
  95. #if (defined _WIN32 || defined _WIN64)
  96. int n = _vscprintf(str, arg);
  97. char* buf = (char*)malloc(n + 1);
  98. vsprintf(buf, str, arg);
  99. auto modifyStr = CSimpleString::Format("%s", buf);
  100. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).withExtendLog(!ConfigManager::getInstance().m_withNoFileLog).setResultMsg(modifyStr.GetData())();
  101. free(buf);
  102. #else
  103. auto modifyStr = CSimpleString::Format("%s", str);
  104. vDbg(modifyStr.GetData(), arg);
  105. #endif
  106. va_end(arg);
  107. }
  108. bool SYSTEM_ON(std::string cmdLine, bool isWait)
  109. {
  110. #if (defined _WIN32 || defined _WIN64)
  111. auto waitSystem = [](const std::string cmd, const std::string par, BOOL nShow) ->DWORD
  112. {
  113. SHELLEXECUTEINFO ShExecInfo = { 0 };
  114. ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
  115. ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
  116. ShExecInfo.hwnd = NULL;
  117. ShExecInfo.lpVerb = NULL;
  118. ShExecInfo.lpFile = cmd.c_str(); //调用的程序名
  119. ShExecInfo.lpParameters = par.c_str(); //调用程序的命令行参数
  120. ShExecInfo.lpDirectory = NULL;
  121. ShExecInfo.nShow = nShow ? SW_SHOW : SW_HIDE; //窗口状态为隐藏
  122. ShExecInfo.hInstApp = NULL;
  123. if (ShellExecuteEx(&ShExecInfo) && ShExecInfo.hProcess)//如果设置了 SEE_MASK_NOCLOSEPROCESS ,并且调用成功则该值大于32,调用失败者被设置错误值
  124. {
  125. //创建进程成功
  126. WaitForSingleObject(ShExecInfo.hProcess, INFINITE); //等到该进程结束
  127. DWORD exitCode = 0;
  128. GetExitCodeProcess(ShExecInfo.hProcess, &exitCode);
  129. return exitCode;
  130. }
  131. else {
  132. std::string errMsg;
  133. auto errorCode = GetLastError();
  134. switch (errorCode)
  135. {
  136. #define CASE(code) \
  137. case code: \
  138. errMsg = #code; \
  139. break
  140. CASE(ERROR_FILE_NOT_FOUND);
  141. CASE(ERROR_PATH_NOT_FOUND);
  142. CASE(ERROR_DDE_FAIL);
  143. CASE(ERROR_NO_ASSOCIATION);
  144. CASE(ERROR_ACCESS_DENIED);
  145. CASE(ERROR_DLL_NOT_FOUND);
  146. CASE(ERROR_CANCELLED);
  147. CASE(ERROR_NOT_ENOUGH_MEMORY);
  148. CASE(ERROR_SHARING_VIOLATION);
  149. default:
  150. errMsg = "UNKNOWN";
  151. }
  152. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("SYSTEM_ON wait with %s failed, reason:%d-%s", par.c_str(), errorCode, errMsg.c_str());
  153. return false;
  154. }
  155. };
  156. std::string strCmd, strPar;
  157. if (isWait)
  158. {
  159. strPar = std::string("/c ") + cmdLine;
  160. strCmd = std::string("cmd ") + strPar;
  161. return waitSystem("cmd.exe", strPar, FALSE);
  162. }
  163. else {
  164. strCmd = cmdLine;
  165. unsigned int result = WinExec(strCmd.c_str(), SW_HIDE);
  166. if (result > 31)
  167. return true;
  168. else
  169. {
  170. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__).setAPI(__FUNCTION__)("SYSTEM_ON nowait with %s failed, reason:%d", result);
  171. return false;
  172. }
  173. }
  174. #else
  175. system(cmdLine.c_str());
  176. return true;
  177. #endif
  178. return false;
  179. }
  180. DWORD SaveCefclientLog(std::string magicStr)
  181. {
  182. std::string dstGuid = magicStr + "_" + CEF_GUID;
  183. try {
  184. auto removeRet = message_queue::remove(dstGuid.c_str());
  185. if (!removeRet)
  186. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("message_queue did not remove!");
  187. boost::interprocess::permissions cur;
  188. cur.set_unrestricted();
  189. message_queue mq(create_only, dstGuid.c_str(), 100, sizeof(cefclientLog), cur);
  190. ConfigManager::getInstance().setUseMagic(true);
  191. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("SaveCefclientLog thread begin");
  192. while (true)
  193. {
  194. cefclientLog t_data;
  195. #if (defined _WIN32 || defined _WIN64)
  196. unsigned int t_recvSize = 0;
  197. #else
  198. unsigned long t_recvSize = 0;
  199. #endif
  200. unsigned int t_priority = 0;
  201. mq.receive(&t_data, sizeof(cefclientLog), t_recvSize, t_priority);
  202. std::string source = std::string(t_data.m_filename) + "(" + std::to_string((ULONGLONG)t_data.m_filePos) + ")";
  203. #ifdef OUTPUT_DETAIL_LOG /*DevOps流水线编译,ST环境*/
  204. DbgWithLink(t_data.m_level, t_data.m_type).withLogProducer(ConfigManager::getInstance().getLogProducer()).setSourceType(source.c_str()).withExtendLog(true).setResultMsg(t_data.m_cefLog)();
  205. #elif defined(DEVOPS_ON_UAT)/*DevOps流水线编译,UAT环境*/
  206. DbgWithLink(t_data.m_level, t_data.m_type).withLogProducer(ConfigManager::getInstance().getLogProducer()).setSourceType(source.c_str()).withExtendLog(true).setResultMsg(t_data.m_cefLog)();
  207. #elif defined(DEVOPS_ON_PRD)/*DevOps流水线编译,PRD环境*/
  208. DbgWithLink(t_data.m_level, t_data.m_type).withLogProducer(ConfigManager::getInstance().getLogProducer()).setSourceType(source.c_str()).withExtendLog(false).setResultMsg(t_data.m_cefLog)();
  209. #else
  210. DbgWithLink(t_data.m_level, t_data.m_type).withLogProducer(ConfigManager::getInstance().getLogProducer()).setSourceType(source.c_str()).withExtendLog(false).setResultMsg(t_data.m_cefLog)();
  211. #endif // DEVOPS
  212. if (sizeof(cefclientLog) != t_recvSize)
  213. break;
  214. /*特么制品库太恶心了
  215. cefclientLog tmp;
  216. std::istringstream iss(t_data);
  217. boost::archive::binary_iarchive iarchive(iss);
  218. iarchive >> tmp;//从一个保存序列化数据的string里面反序列化,从而得到原来的对象
  219. std::string source = tmp.m_filename + "(" + std::to_string((ULONGLONG)tmp.m_filePos) + ")";
  220. DbgWithLink(tmp.m_level, tmp.m_type).setSourceType(source.c_str())(tmp.m_cefLog.c_str());
  221. */
  222. }
  223. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("SaveCefclientLog thread end");
  224. }
  225. catch (interprocess_exception& ex) {
  226. message_queue::remove(dstGuid.c_str());
  227. ConfigManager::getInstance().setUseMagic(false);
  228. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("%s run exception, for %s", dstGuid.c_str(), ex.what());
  229. return 1;
  230. }
  231. ConfigManager::getInstance().setUseMagic(false);
  232. message_queue::remove(dstGuid.c_str());
  233. return 0;
  234. }
  235. std::vector<std::string> find_files(const std::string srcPath, const std::string fileName, bool isDir)
  236. {
  237. std::vector<std::string> ret;
  238. static boost::xpressive::sregex_compiler rc;
  239. if (!rc[fileName].regex_id())
  240. {
  241. std::string str = boost::algorithm::replace_all_copy(
  242. boost::algorithm::replace_all_copy(fileName, ".", "\\."), "*", ".*");
  243. rc[fileName] = rc.compile(str);
  244. }
  245. try {
  246. if (!boost::filesystem::exists(srcPath) || !boost::filesystem::is_directory(srcPath))
  247. return ret;
  248. typedef boost::filesystem::recursive_directory_iterator rd_iterator;
  249. rd_iterator end;
  250. for (rd_iterator pos(srcPath); pos != end; ++pos)
  251. {
  252. if ((isDir ? boost::filesystem::is_directory(*pos) : !boost::filesystem::is_directory(*pos)) && boost::xpressive::regex_match(pos->path().filename().string(), rc[fileName]))
  253. ret.emplace_back(pos->path().string());
  254. }
  255. }
  256. catch (const boost::filesystem::filesystem_error& e) {
  257. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Error: %s", e.what());
  258. }
  259. return ret;
  260. }
  261. bool deleteDir_byFileSystem(const std::string srcPath)
  262. {
  263. boost::system::error_code ec;
  264. return boost::filesystem::remove_all(srcPath, ec);
  265. }
  266. std::string generateTimeStr(bool isSimple)
  267. {
  268. auto tt = boost::chrono::system_clock::to_time_t(boost::chrono::system_clock::now());
  269. struct tm* ptm = localtime(&tt);
  270. char date[60] = { 0 };
  271. if (isSimple)
  272. sprintf(date, "%02d%02d%02d", (int)ptm->tm_hour, (int)ptm->tm_min, (int)ptm->tm_sec);
  273. else
  274. sprintf(date, "%d-%02d-%02d-%02d:%02d:%02d", (int)ptm->tm_year + 1900, (int)ptm->tm_mon + 1, (int)ptm->tm_mday, (int)ptm->tm_hour, (int)ptm->tm_min, (int)ptm->tm_sec);
  275. return std::string(date);
  276. }
  277. void InitTranslateFile(std::string srcFile)
  278. {
  279. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("InitTranslateFile %s", srcFile.c_str());
  280. g_usercodeTranslateFile = srcFile;
  281. }
  282. void InitUserCodeToMsgTip(CAutoArray<CSimpleStringA>& strErrorCodeArr, CAutoArray<CSimpleStringA>& strDescriptionArr, CAutoArray<CSimpleStringA>& strRemarkArr)
  283. {
  284. g_UserCodeToMsgTip.clear();//should not be inited muli times
  285. for (int i = 0; i < strErrorCodeArr.GetCount(); i++)
  286. {
  287. std::string dstDescribe = "[" + std::string(strErrorCodeArr[i].GetData()) + "]" + std::string(strDescriptionArr[i].GetData());
  288. if (g_UserCodeToMsgTip.find(strRemarkArr[i].GetData()) != g_UserCodeToMsgTip.end())
  289. {
  290. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("InitUserCodeToMsgTip repeated usercode:%s", strRemarkArr[i].GetData());
  291. continue;
  292. }
  293. std::string curRemark = strRemarkArr[i].GetData();
  294. std::transform(curRemark.begin(), curRemark.end(), curRemark.begin(), [](unsigned char c) { return std::tolower(c); });
  295. g_UserCodeToMsgTip.insert(std::make_pair(curRemark.c_str(), ErrMsgStruct(strErrorCodeArr[i].GetData(), dstDescribe, curRemark.c_str())));
  296. }
  297. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("InitUserCodeToMsgTip size:%d", g_UserCodeToMsgTip.size());
  298. }
  299. bool isMsgTipExist()
  300. {
  301. return g_UserCodeToMsgTip.size() > 0;
  302. }
  303. std::pair<unsigned long, ErrMsgStruct> getErrMsgByRemark(std::string srcMsg, bool isSafe)
  304. {
  305. const std::string headerStr = "UserError=";
  306. if (srcMsg.find(headerStr) != 0)
  307. if(isSafe)
  308. return std::make_pair(0, ErrMsgStruct("RTA42F1", CSimpleString::Format("[RTA42F1]错误映射异常|(%s)", srcMsg.c_str()).GetData(), ""));
  309. else
  310. return std::make_pair(0, ErrMsgStruct("", srcMsg, ""));
  311. unsigned long userCode = std::stoi(srcMsg.substr(headerStr.length()));
  312. std::string userCodeStr = CSimpleString::Format("0x%X", userCode).GetData();
  313. std::transform(userCodeStr.begin(), userCodeStr.end(), userCodeStr.begin(), [](unsigned char c) { return std::tolower(c); });
  314. if (g_UserCodeToMsgTip.size() == 0)
  315. {
  316. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA42F0").setAPI(__FUNCTION__)("[RTA42F0]微服务异常|(%s)", srcMsg.c_str());
  317. return std::make_pair(0, ErrMsgStruct("RTA42F0", CSimpleString::Format("[RTA42F0]微服务异常|(%s)", srcMsg.c_str()).GetData(), userCodeStr));
  318. }
  319. if (g_UserCodeToMsgTip.find(userCodeStr) != g_UserCodeToMsgTip.end())
  320. {
  321. ErrMsgStruct curMsg(g_UserCodeToMsgTip[userCodeStr]);
  322. return std::make_pair(userCode, curMsg);
  323. }
  324. else
  325. {
  326. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA42F1").setAPI(__FUNCTION__)("[RTA42F1]错误映射异常|(%s)", srcMsg.c_str());
  327. return std::make_pair(userCode, ErrMsgStruct("RTA42F1", CSimpleString::Format("[RTA42F1]错误映射异常|(%s)", srcMsg.c_str()).GetData(), userCodeStr));
  328. }
  329. }
  330. std::string hexdumpToString(const char* buf, const int num)
  331. {
  332. char str[8192 * 2] = { 0 };
  333. int i = 0;
  334. char c[5] = { 0 };
  335. if (num > 100)
  336. {
  337. for (i = 0; i < 50; i++)
  338. {
  339. sprintf(c, "%02X ", (unsigned char)buf[i]);
  340. strcat(str, c);
  341. }
  342. return CSimpleStringA::Format("buffer too long to show!show pre 50 hex! CSocketClient hex buf len = %d : %s", num, str).GetData();
  343. }
  344. for (i = 0; i < num; i++)
  345. {
  346. sprintf(c, "%02X ", (unsigned char)buf[i]);
  347. strcat(str, c);
  348. }
  349. return CSimpleStringA::Format("CSocketClient hex buf len = %d : %s", num, str).GetData();
  350. }
  351. void hexdump(const char* buf, const int num) {
  352. auto hexStr = hexdumpToString(buf, num);
  353. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)(hexStr.c_str());
  354. }
  355. bool modifyBySpecialStr(std::wstring& src)
  356. {
  357. #if 0
  358. clock_t cur = clock();
  359. std::set<wchar_t> srcArr;
  360. static std::set<wchar_t> compareArr;
  361. for (auto it = src.begin(); it != src.end(); it++)
  362. srcArr.insert(*it);
  363. if (compareArr.size() == 0)
  364. {
  365. for (auto it = specialStr.begin(); it != specialStr.end(); it++)
  366. compareArr.insert(*it);
  367. }
  368. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("modifyBySpecialStr insert cost:%d", clock() - cur);
  369. cur = clock();
  370. std::set<wchar_t> result;
  371. std::set_intersection(std::begin(srcArr), std::end(srcArr), std::begin(compareArr), std::end(compareArr), std::inserter(result, std::begin(result)));
  372. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("modifyBySpecialStr intersection cost:%d", clock() - cur);
  373. cur = clock();
  374. if (result.size() == 0)
  375. return false;
  376. for (auto it = result.begin(); it != result.end(); it++)
  377. {
  378. int pos = 0;
  379. for (int pos = 0; pos < src.length();)
  380. {
  381. pos = src.find(*it, pos);
  382. if (pos < 0)
  383. break;
  384. if (pos + 1 < src.length() && src[pos + 1] == '\\')
  385. src.erase(pos + 1, 1);
  386. else
  387. pos++;
  388. }
  389. }
  390. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("modifyBySpecialStr modify cost:%d", clock() - cur);
  391. cur = clock();
  392. return true;
  393. #endif
  394. clock_t cur = clock();
  395. wchar_t specialone = L'碶';
  396. if (src.find(specialone, 0) == -1)
  397. return false;
  398. int pos = 0;
  399. for (int pos = 0; pos < src.length();)
  400. {
  401. pos = src.find(specialone, pos);
  402. if (pos < 0)
  403. break;
  404. if (pos + 1 < src.length() && src[pos + 1] == '\\')
  405. src.erase(pos + 1, 1);
  406. else
  407. pos++;
  408. }
  409. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("modifyBySpecialStr modify cost:%d", clock() - cur);
  410. return true;
  411. }
  412. #include <boost/stacktrace.hpp>
  413. #if (defined _WIN32 || defined _WIN64)
  414. long WINAPI printSEG(struct _EXCEPTION_POINTERS* ExceptionInfo)
  415. #else
  416. long printSEG()
  417. #endif
  418. {
  419. auto dumpArr = boost::stacktrace::stacktrace().as_vector();
  420. if (dumpArr.size() > 20)
  421. {
  422. for (auto i = 0; i < 10; i++)
  423. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("Pre SEG[%d]%X---%s(%s-%d)", i, dumpArr[i].address(), dumpArr[i].name().c_str(), dumpArr[i].source_file().c_str(), dumpArr[i].source_line());
  424. for (auto i = dumpArr.size() - 10; i < dumpArr.size(); i++)
  425. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("Post SEG[%d]%X---%s(%s-%d)", i, dumpArr[i].address(), dumpArr[i].name().c_str(), dumpArr[i].source_file().c_str(), dumpArr[i].source_line());
  426. }
  427. else
  428. {
  429. for (auto i = 0; i < dumpArr.size(); i++)
  430. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("SEG[%d]%X---%s(%s-%d)", i, dumpArr[i].address(), dumpArr[i].name().c_str(), dumpArr[i].source_file().c_str(), dumpArr[i].source_line());
  431. }
  432. return 0;
  433. }
  434. //singal,退出函数
  435. #if (defined _WIN32 || defined _WIN64)
  436. #else
  437. #include <signal.h> // ::signal, ::raise
  438. #include <boost/stacktrace.hpp>
  439. #include "CModTools.h"
  440. #include "CWebsocketServer.h"
  441. #include <winpr/sysinfo.h>
  442. #include <winpr/timezone.h>
  443. std::string g_backtracePath = "";
  444. void seg_signal_handler(int signum)
  445. {
  446. //boost::stacktrace::safe_dump_to(g_backtracePath.c_str());
  447. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("receive signal:%d, seg_signal_handler", signum);
  448. printSEG();
  449. Chromium::CModTools::get_mutable_instance().killAllChromium();
  450. Chromium::CWebsocketServer::stopServer();
  451. signal(signum, SIG_DFL);
  452. raise(signum);
  453. }
  454. void normal_signal_handle(int signum)
  455. {
  456. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("receive signal:%d, normal_signal_handle", signum);
  457. signal(signum, SIG_DFL);
  458. raise(signum);
  459. }
  460. void set_traceback_path(std::string path)
  461. {
  462. g_backtracePath = path + "/mod_chromium/" + generateTimeStr(true) + "_chromium_backtrace.dump";
  463. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("set_traceback_path %s", g_backtracePath.c_str());
  464. }
  465. #endif
  466. void receivehexdump(const char* buf, const int num) {
  467. char str[8192 * 2] = { 0 };
  468. int i = 0;
  469. char c[5] = { 0 };
  470. if (num > 100)
  471. {
  472. for (i = 0; i < 50; i++)
  473. {
  474. sprintf(c, "%02X ", (unsigned char)buf[i]);
  475. strcat(str, c);
  476. }
  477. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("buffer too long to show!show pre 50 hex! receivehexdump hex buf len = %d : %s", num, str);
  478. return;
  479. }
  480. for (i = 0; i < num; i++)
  481. {
  482. sprintf(c, "%02X ", (unsigned char)buf[i]);
  483. strcat(str, c);
  484. }
  485. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("receivehexdump hex buf len = %d : %s", num, str);
  486. return;
  487. }
  488. void doWithDebugModeData(const char* strMethod, const char* buf)
  489. {
  490. boost::lock_guard<boost::mutex> lock(g_networkMutex);
  491. if(std::string(strMethod).find("Network.") == 0)
  492. {
  493. /*for example
  494. {
  495. "method": "Network.requestWillBeSent",
  496. "params": {
  497. "documentURL": "https://www.btbtt12.com/",
  498. "frameId": "8F58093A23334B311DB645BA3652E63C",
  499. "hasUserGesture": false,
  500. "initiator": {
  501. "type": "other"
  502. },
  503. "loaderId": "9F7B28B896C791554C69C5985CA92E79",
  504. "request": {
  505. "headers": {
  506. "Referer": "https://www.btbtt12.com/",
  507. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36"
  508. },
  509. "initialPriority": "Low",
  510. "method": "GET",
  511. "mixedContentType": "none",
  512. "referrerPolicy": "no-referrer-when-downgrade",
  513. "url": "https://pic.picnewsss.com/tu-2022290039/960-60.gif"
  514. },
  515. "requestId": "18476.34",
  516. "timestamp": 19338.811603,
  517. "type": "Image",
  518. "wallTime": 1666099893.800733
  519. }
  520. }
  521. */
  522. std::shared_ptr<cJSON> pJson(cJSON_Parse(buf), [](cJSON* p) {
  523. if (nullptr != p)
  524. cJSON_Delete(p);
  525. });
  526. auto paramsItem = cJSON_GetObjectItem(pJson.get(), "params");
  527. if (paramsItem == nullptr)
  528. return;
  529. auto requestIdItem = cJSON_GetObjectItem(paramsItem, "requestId");
  530. if (requestIdItem == nullptr)
  531. return;
  532. std::string requestId_str = requestIdItem->valuestring;
  533. /*
  534. ['Network.loadingFailed', 'Network.loadingFinished', 'Network.resourceChangedPriority',
  535. 'Network.requestServedFromCache', 'Network.requestWillBeSent', 'Network.requestWillBeSentExtraInfo',
  536. 'Network.responseReceived', 'Network.responseReceivedExtraInfo', 'Network.dataReceived',
  537. 'Page.frameAttached', 'Page.frameRequestedNavigation', 'Page.frameStoppedLoading',
  538. 'Page.frameClearedScheduledNavigation', 'Page.loadEventFired', 'Page.frameStartedLoading',
  539. 'Page.frameDetached', 'Page.frameScheduledNavigation', 'Page.frameNavigated', 'Page.frameResized',
  540. 'Page.domContentEventFired']
  541. */
  542. if(std::string(strMethod) == "Network.loadingFinished")
  543. {
  544. if (g_networkParse.find(requestId_str) != g_networkParse.end())
  545. g_networkParse.erase(requestId_str);
  546. if (g_networkExpiredData.find(requestId_str) != g_networkExpiredData.end())
  547. g_networkExpiredData.erase(requestId_str);
  548. if (g_networkExpiredData.size() < 30)
  549. return;
  550. for(auto it = g_networkExpiredData.begin(); it != g_networkExpiredData.end();)
  551. {
  552. if((clock() - it -> second) < 100000)
  553. {
  554. it++;
  555. continue;
  556. }
  557. if (g_networkParse.find(it->first) != g_networkParse.end())
  558. g_networkParse.erase(it->first);
  559. g_networkExpiredData.erase(it++);
  560. }
  561. }
  562. else if(std::string(strMethod) == "Network.loadingFailed"
  563. || std::string(strMethod) == "Network.webSocketFrameError"
  564. || std::string(strMethod) == "Network.requestServedFromCache")
  565. {
  566. if (g_networkParse.find(requestId_str) != g_networkParse.end())
  567. {
  568. for(auto it = g_networkParse[requestId_str].begin(); it != g_networkParse[requestId_str].end(); it++)
  569. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode("QLR0402402Z00001").setResultMsg(it->c_str())();
  570. g_networkParse.erase(requestId_str);
  571. }
  572. else//此时,上一轮记录已结束
  573. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402402Z00001").setResultMsg(buf)();
  574. if (g_networkExpiredData.find(requestId_str) != g_networkExpiredData.end())
  575. g_networkExpiredData.erase(requestId_str);
  576. }
  577. else
  578. {
  579. if (g_networkParse.find(requestId_str) != g_networkParse.end())
  580. g_networkParse[requestId_str].push_back(buf);
  581. else
  582. {
  583. std::vector<std::string> tmp;
  584. tmp.push_back(buf);
  585. g_networkParse[requestId_str] = tmp;
  586. g_networkExpiredData[requestId_str] = clock();
  587. }
  588. }
  589. }
  590. if (std::string(strMethod) == "Network.webSocketFrameError" ||
  591. std::string(strMethod) == "Network.loadingFailed" ||
  592. std::string(strMethod) == "Runtime.exceptionThrown")
  593. {
  594. LogWarn(Severity_Middle, Error_Debug, LOG_WARN_CHROMIUM_OPENWEBWARN, buf);
  595. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402402Z00002").setResultMsg(buf)();
  596. }
  597. }
  598. std::pair<bool, CSimpleStringA> json_deal::getStringFromCjsonObj(void* object, const char* name)
  599. {
  600. if (object == NULL)
  601. return std::make_pair(false, "");
  602. auto curNode = cJSON_GetObjectItem((cJSON*)object, name);
  603. if (curNode && curNode->type == cJSON_String) {
  604. return std::make_pair(true, curNode->valuestring);
  605. }
  606. else
  607. return std::make_pair(false, "");
  608. }
  609. std::pair<bool, int> json_deal::getIntergerFromCjsonObj(void* object, const char* name)
  610. {
  611. if (object == NULL)
  612. return std::make_pair(false, 0);
  613. auto curNode = cJSON_GetObjectItem((cJSON*)object, name);
  614. if (curNode && curNode->type == cJSON_Number) {
  615. return std::make_pair(true, curNode->valueint);
  616. }
  617. else
  618. return std::make_pair(false, 0);
  619. }
  620. std::pair<bool, double> json_deal::getDoubleFromCjsonObj(void* object, const char* name)
  621. {
  622. if (object == NULL)
  623. return std::make_pair(false, 0);
  624. auto curNode = cJSON_GetObjectItem((cJSON*)object, name);
  625. if (curNode && curNode->type == cJSON_Number) {
  626. return std::make_pair(true, curNode->valuedouble);
  627. }
  628. else
  629. return std::make_pair(false, 0);
  630. }
  631. SM2_Encrypt_Manager::SM2_Encrypt_Manager()
  632. :m_public_key_buf_len(DEFAULT_KEY_LEN),
  633. m_private_key_buf_len(DEFAULT_KEY_LEN),
  634. m_opposite_public_key_buf_len(DEFAULT_KEY_LEN)
  635. {
  636. memset(m_public_key_buf, 0, DEFAULT_KEY_LEN);
  637. memset(m_private_key_buf, 0, DEFAULT_KEY_LEN);
  638. memset(m_opposite_public_key_buf, 0, DEFAULT_KEY_LEN);
  639. GenerateSM2_key(m_public_key, m_private_key);
  640. m_state = SM2ProtocolState::WAIT_KEY_EXCHANGE;
  641. }
  642. SM2_Encrypt_Manager::~SM2_Encrypt_Manager()
  643. {
  644. }
  645. bool SM2_Encrypt_Manager::GenerateSM2_key(std::string& pub, std::string& pri)
  646. {
  647. if (!::CreateSM2KeyPair(m_public_key_buf, &m_public_key_buf_len, m_private_key_buf, &m_private_key_buf_len))
  648. return false;
  649. pub = binToHex(m_public_key_buf, m_public_key_buf_len);
  650. pri = binToHex(m_private_key_buf, m_private_key_buf_len);
  651. return true;
  652. }
  653. std::string SM2_Encrypt_Manager::binToHex(const unsigned char* data, int len)
  654. {
  655. std::string hexString;
  656. // 使用 boost::algorithm::hex 进行编码
  657. boost::algorithm::hex(data, data + len, std::back_inserter(hexString));
  658. return hexString;
  659. }
  660. void SM2_Encrypt_Manager::hexToBin(const std::string& hexStr, unsigned char* binData, int& binLen)
  661. {
  662. binLen = hexStr.size() / 2;
  663. if (binData == nullptr) {
  664. // 如果 binData 为 nullptr,仅返回计算出的 binLen,不执行实际的转换
  665. return;
  666. }
  667. // 使用 boost::algorithm::unhex 进行解码
  668. boost::algorithm::unhex(hexStr.begin(), hexStr.end(), binData);
  669. }
  670. void SM2_Encrypt_Manager::setOpposite(const std::string pub)
  671. {
  672. m_opposite_public_key = pub;
  673. hexToBin(m_opposite_public_key, m_opposite_public_key_buf, m_opposite_public_key_buf_len);
  674. }
  675. std::pair<bool, std::string> SM2_Encrypt_Manager::checkSM2Enable()
  676. {
  677. if (m_public_key.length() == 0)
  678. return std::make_pair(false, "public_key is empty");
  679. if (m_private_key.length() == 0)
  680. return std::make_pair(false, "private_key is empty");
  681. if (m_opposite_public_key.length() == 0)
  682. return std::make_pair(false, "opposite public_key is empty");
  683. return std::make_pair(true, "");
  684. }
  685. std::pair<std::string, std::string> SM2_Encrypt_Manager::EncryptMsg(std::string msg)
  686. {
  687. unsigned char sign[DEFAULT_KEY_LEN] = "";
  688. int sign_len = DEFAULT_KEY_LEN;
  689. unsigned char* dstMsg = new unsigned char[msg.length() * 2 + 97];
  690. int dstMsgLen = msg.length() * 2 + 97;
  691. std::shared_ptr<void> msgClean((void*)0, [&](void*) {
  692. if (dstMsg)
  693. {
  694. delete[]dstMsg;
  695. dstMsg = nullptr;
  696. }
  697. });
  698. if (!SM2SignWithSM3(m_private_key_buf, m_private_key_buf_len, (unsigned char*)msg.c_str(), msg.length(), sign, &sign_len))
  699. {
  700. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("SM2SignWithSM3::err, can not sign msg, sign_len:%d", sign_len);
  701. return std::make_pair("", "");
  702. }
  703. if(!EncWithSM2PubKey((unsigned char*)msg.c_str(), msg.length(), dstMsg, &dstMsgLen, m_opposite_public_key_buf, m_opposite_public_key_buf_len))
  704. {
  705. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("EncWithSM2PubKey::err, can not encrypt msg, m_opposite_public_key_buf_len: %d", m_opposite_public_key_buf_len);
  706. return std::make_pair("", "");
  707. }
  708. return std::make_pair(binToHex(sign, sign_len), binToHex(dstMsg, dstMsgLen));
  709. }
  710. std::pair<bool, std::string> SM2_Encrypt_Manager::DecryptMsg(std::string sign, std::string msg)
  711. {
  712. unsigned char* binMsg = new unsigned char[msg.length()], *outMsg = new unsigned char[msg.length() * 2], *binSign = new unsigned char[sign.length()];//normally, it is half length of msg
  713. int binMsgLen = msg.length(), outMsgLen = msg.length() * 2, signLen = sign.length();
  714. std::shared_ptr<void> msgClean((void*)0, [&](void*) {
  715. if (binMsg) {
  716. delete[] binMsg;
  717. binMsg = nullptr;
  718. }
  719. if (outMsg) {
  720. delete[] outMsg;
  721. outMsg = nullptr;
  722. }
  723. if (binSign) {
  724. delete[] binSign;
  725. binSign = nullptr;
  726. }
  727. });
  728. hexToBin(msg, binMsg, binMsgLen);
  729. hexToBin(sign, binSign, signLen);
  730. if (!DecWithSM2PriKey(binMsg, binMsgLen, outMsg, &outMsgLen, m_private_key_buf, m_private_key_buf_len))
  731. return std::make_pair(false, "DecWithSM2PriKey::err, can not dectrypt msg");
  732. if (!SM2VerifyWithSM3(m_opposite_public_key_buf, m_opposite_public_key_buf_len, outMsg, outMsgLen, binSign, signLen))
  733. return std::make_pair(false, "SM2VerifyWithSM3::err, can not verify sign");
  734. return std::make_pair(true, (char*)outMsg);
  735. }
  736. std::pair<bool, std::string> SM2_Encrypt_Manager::GenerateEncPubKey()
  737. {
  738. if(!verifySM2Manager())
  739. return std::make_pair(false, "GenerateEncPubKey::verifySM2Manager err");
  740. unsigned char encPubKey[DEFAULT_KEY_LEN] = "";
  741. int encPubKey_len = DEFAULT_KEY_LEN;
  742. if(!EncWithSM2PubKey(m_public_key_buf, m_public_key_buf_len, encPubKey, &encPubKey_len, m_opposite_public_key_buf, m_opposite_public_key_buf_len))
  743. return std::make_pair(false, "GenerateEncPubKey::EncWithSM2PubKey err");
  744. return std::make_pair(true, binToHex(encPubKey, encPubKey_len));
  745. }
  746. bool SM2_Encrypt_Manager::verifySM2Manager()
  747. {
  748. if (m_opposite_public_key.length() == 0 || m_public_key.length() == 0 || m_private_key.length() == 0)
  749. return false;
  750. if (m_opposite_public_key_buf == NULL || m_public_key_buf == NULL || m_private_key_buf == NULL)
  751. return false;
  752. return true;
  753. }
  754. #ifdef RVC_OS_LINUX
  755. std::vector<int> getUosBrowserPIDs(int UseUOSBrowser)
  756. {
  757. std::vector<int> pids;
  758. FILE* fp = nullptr;
  759. if(UseUOSBrowser == 1)
  760. fp = popen("ps -ef | grep uosbrowser | grep -v grep | awk '{print $2}'", "r");
  761. else if(UseUOSBrowser == 2)
  762. fp = popen("ps -ef | grep browser | grep -v grep | awk '{print $2}'", "r");
  763. if (fp) {
  764. char buffer[256];
  765. while (fgets(buffer, sizeof(buffer), fp) != NULL) {
  766. pids.push_back(static_cast<pid_t>(std::atoi(buffer)));
  767. }
  768. pclose(fp);
  769. }
  770. return pids;
  771. }
  772. #endif
  773. ConfigManager& ConfigManager::getInstance() {
  774. static ConfigManager instance;
  775. return instance;
  776. }
  777. ConfigManager::ConfigManager()
  778. : m_iTcpBridgePort(4504), m_strCustomMainUrl(""), m_strCustomAdUrl(""), m_runAd(false), m_runMain(false), m_runExtend(false), m_runLogin(false), m_withBrowser(false), m_withMin(false), m_withClose(false)
  779. , m_withDebugMode(false), m_withMagic(false), m_withNoFileLog(false), m_installMode(false), m_withMedia(false), m_withSpecialTest(false), m_withConsole(false),
  780. m_withLinkLog(false), m_withUnsafeAd(false), m_withUnsafeMain(false), m_noStartupPage(false), m_extension_debugOpen(false), m_extension_withTerminal(false)
  781. {
  782. void* logProducer = nullptr;
  783. std::map<std::string, void*> g_logProducerArr;
  784. bool g_useMagic = false;
  785. bool g_loggerInitSuccess = false;
  786. bool g_withSpecialTest = false;
  787. bool g_hasInitCfg = false;//can discard
  788. int g_sogouForce = 0;
  789. m_extensionPath = "";
  790. }
  791. LogManager& LogManager::getInstance() {
  792. static LogManager instance;
  793. return instance;
  794. }
  795. void LogManager::logWebSocketBuild(int64_t hdl, const std::string& url, const std::string& isSecurity) {
  796. const char* type = "ws_build";
  797. Json::Value log;
  798. log["hdl"] = Json::Int64(hdl);
  799. log["78173721_logType"] = type;
  800. m_logTotal[hdl][type].num += 1;
  801. Json::Value detail;
  802. detail["url"] = url;
  803. detail["isSecurity"] = isSecurity;
  804. log["detail"] = detail;
  805. log["timestamp"] = getCurrentTimestamp();
  806. if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
  807. log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
  808. log["threadId"] = Json::Int64(GetCurrentThreadId());
  809. writeLog(LOG_LEVEL_DEBUG, log);
  810. }
  811. void LogManager::writeLog(LOG_LEVEL_E level, const Json::Value& log) {
  812. Json::FastWriter writer;
  813. DbgWithLink(level, LOG_TYPE_SYSTEM)(writer.write(log).c_str());
  814. }
  815. std::string LogManager::getCurrentTimestamp() {
  816. /*
  817. FILETIME ft;
  818. SYSTEMTIME st;
  819. GetSystemTime(&st);
  820. SystemTimeToFileTime(&st, &ft);
  821. FILETIME utc_ft, local_ft;
  822. #ifdef _WIN32
  823. utc_ft.dwLowDateTime = (DWORD)ft.dwLowDateTime;
  824. utc_ft.dwHighDateTime = (DWORD)ft.dwHighDateTime;
  825. FileTimeToLocalFileTime(&utc_ft, &local_ft);
  826. FileTimeToSystemTime(&local_ft, &st);
  827. #else
  828. GetLocalTime(&st);
  829. #endif // _WIN32
  830. */
  831. using namespace std::chrono;
  832. auto now = system_clock::now();
  833. auto ms = duration_cast<milliseconds>(now.time_since_epoch()) % 1000;
  834. auto timer = system_clock::to_time_t(now);
  835. std::ostringstream oss;
  836. oss << std::put_time(std::localtime(&timer), "%Y-%m-%d %H:%M:%S")
  837. << '.' << std::setfill('0') << std::setw(3) << ms.count();
  838. return oss.str();
  839. }
  840. void LogManager::logWebSocketBeginSession(int64_t hdl,
  841. int64_t web_transID,
  842. int64_t inner_transID,
  843. const std::string& entity,
  844. const std::string& entityClass,
  845. int ret,
  846. const std::string& operate,
  847. const std::string& payload,
  848. int retDetail,
  849. const std::string& reason) {
  850. const char* type = "ws_beginSession";
  851. Json::Value log;
  852. log["hdl"] = Json::Int64(hdl);
  853. log["78173721_logType"] = type;
  854. m_logTotal[hdl][type].num += 1;
  855. Json::Value detail;
  856. detail["web_transID"] = web_transID;
  857. detail["inner_transID"] = inner_transID;
  858. detail["entity"] = entity;
  859. detail["class"] = entityClass;
  860. detail["ret"] = ret;
  861. detail["retDetail"] = retDetail;
  862. detail["reason"] = reason;
  863. detail["operate"] = operate;
  864. #ifdef OUTPUT_DETAIL_LOG
  865. detail["payload"] = payload;
  866. #endif
  867. log["detail"] = detail;
  868. log["timestamp"] = getCurrentTimestamp();
  869. if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
  870. log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
  871. log["threadId"] = Json::Int64(GetCurrentThreadId());
  872. writeLog(LOG_LEVEL_DEBUG, log);
  873. }
  874. void LogManager::logWebSocketClose(int64_t hdl) {
  875. const char* type = "ws_close";
  876. Json::Value log;
  877. log["hdl"] = Json::Int64(hdl);
  878. log["78173721_logType"] = type;
  879. m_logTotal[hdl][type].num += 1;
  880. log["timestamp"] = getCurrentTimestamp();
  881. if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
  882. log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
  883. log["threadId"] = Json::Int64(GetCurrentThreadId());
  884. Json::Value root(Json::objectValue);
  885. if (m_logTotal.find(hdl) != m_logTotal.end())
  886. {
  887. // 遍历 map
  888. for (const auto& pair : m_logTotal[hdl]) {
  889. std::string key = pair.first;
  890. const LogInfo& logInfo = pair.second;
  891. root[key] = logInfo.num;
  892. }
  893. log["dealed"] = root;
  894. m_logTotal.erase(hdl);
  895. }
  896. writeLog(LOG_LEVEL_INFO, log);
  897. }
  898. void LogManager::logWebSocketInfo(int64_t hdl,
  899. int64_t web_transID,
  900. int64_t sessionId,
  901. const std::string& entity,
  902. const std::string& function,
  903. int ret,
  904. const std::string& operate,
  905. int retDetail,
  906. const std::string& reason,
  907. const std::string& payload) {
  908. const char* type = "ws_info";
  909. Json::Value log;
  910. log["hdl"] = Json::Int64(hdl);
  911. log["78173721_logType"] = type;
  912. m_logTotal[hdl][type].num += 1;
  913. Json::Value detail;
  914. detail["web_transID"] = Json::Int64(web_transID);
  915. detail["sessionId"] = Json::Int64(sessionId);
  916. detail["entity"] = entity;
  917. detail["function"] = function;
  918. detail["ret"] = ret;
  919. detail["operate"] = operate;
  920. detail["retDetail"] = retDetail;
  921. detail["reason"] = reason;
  922. #ifdef OUTPUT_DETAIL_LOG
  923. detail["payload"] = payload;
  924. #endif
  925. log["detail"] = detail;
  926. log["timestamp"] = getCurrentTimestamp();
  927. if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
  928. log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
  929. log["threadId"] = Json::Int64(GetCurrentThreadId());
  930. writeLog(LOG_LEVEL_DEBUG, log);
  931. }
  932. void LogManager::logWebSocketRegister(int64_t hdl,
  933. int64_t web_transID,
  934. int64_t inner_transID,
  935. const std::string& entity,
  936. const std::string& entityClass,
  937. int ret,
  938. const std::string& operate,
  939. const std::string& payload,
  940. int retDetail,
  941. const std::string& reason) {
  942. const char* type = "ws_register";
  943. Json::Value log;
  944. log["hdl"] = Json::Int64(hdl);
  945. log["78173721_logType"] = type;
  946. m_logTotal[hdl][type].num += 1;
  947. Json::Value detail;
  948. detail["web_transID"] = Json::Int64(web_transID);
  949. detail["inner_transID"] = Json::Int64(inner_transID);
  950. detail["entity"] = entity;
  951. detail["class"] = entityClass;
  952. detail["ret"] = ret;
  953. detail["operate"] = operate;
  954. #ifdef OUTPUT_DETAIL_LOG
  955. detail["payload"] = payload;
  956. #endif
  957. detail["retDetail"] = retDetail;
  958. detail["reason"] = reason;
  959. log["detail"] = detail;
  960. log["timestamp"] = getCurrentTimestamp();
  961. if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
  962. log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
  963. log["threadId"] = Json::Int64(GetCurrentThreadId());
  964. writeLog(LOG_LEVEL_DEBUG, log);
  965. }
  966. void LogManager::logWebSocketRequest(int64_t hdl,
  967. int64_t web_transID,
  968. int64_t inner_transID,
  969. int64_t sessionId,
  970. const std::string& entity,
  971. const std::string& function,
  972. int ret,
  973. const std::string& operate,
  974. const std::string& payload,
  975. int retDetail,
  976. const std::string& reason) {
  977. const char* type = "ws_request";
  978. Json::Value log;
  979. log["hdl"] = Json::Int64(hdl);
  980. log["78173721_logType"] = type;
  981. m_logTotal[hdl][type].num += 1;
  982. Json::Value detail;
  983. detail["web_transID"] = Json::Int64(web_transID);
  984. detail["inner_transID"] = Json::Int64(inner_transID);
  985. detail["sessionId"] = Json::Int64(sessionId);
  986. detail["entity"] = entity;
  987. detail["function"] = function;
  988. detail["ret"] = ret;
  989. detail["operate"] = operate;
  990. detail["retDetail"] = retDetail;
  991. detail["reason"] = reason;
  992. #ifdef OUTPUT_DETAIL_LOG
  993. detail["payload"] = payload;
  994. #endif
  995. log["detail"] = detail;
  996. log["timestamp"] = getCurrentTimestamp();
  997. if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
  998. log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
  999. log["threadId"] = Json::Int64(GetCurrentThreadId());
  1000. writeLog(LOG_LEVEL_DEBUG, log);
  1001. }
  1002. void LogManager::logWebSocketSetVar(int64_t hdl,
  1003. int64_t web_transID,
  1004. int64_t inner_transID,
  1005. const std::string& name,
  1006. const std::string& value,
  1007. int ret,
  1008. const std::string& operate,
  1009. const std::string& payload,
  1010. int retDetail,
  1011. const std::string& reason) {
  1012. const char* type = "ws_setvar";
  1013. Json::Value log;
  1014. log["hdl"] = Json::Int64(hdl);
  1015. log["78173721_logType"] = type;
  1016. m_logTotal[hdl][type].num += 1;
  1017. Json::Value detail;
  1018. detail["web_transID"] = Json::Int64(web_transID);
  1019. detail["inner_transID"] = Json::Int64(inner_transID);
  1020. detail["name"] = name;
  1021. detail["value"] = value;
  1022. detail["ret"] = ret;
  1023. detail["operate"] = operate;
  1024. detail["retDetail"] = retDetail;
  1025. detail["reason"] = reason;
  1026. #ifdef OUTPUT_DETAIL_LOG
  1027. detail["payload"] = payload;
  1028. #endif
  1029. log["detail"] = detail;
  1030. log["timestamp"] = getCurrentTimestamp();
  1031. if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
  1032. log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
  1033. log["threadId"] = Json::Int64(GetCurrentThreadId());
  1034. writeLog(LOG_LEVEL_DEBUG, log);
  1035. }
  1036. void LogManager::logWebSocketGetVar(int64_t hdl,
  1037. int64_t web_transID,
  1038. int64_t inner_transID,
  1039. const std::string& name,
  1040. int ret,
  1041. const std::string& operate,
  1042. const std::string& payload,
  1043. int retDetail,
  1044. const std::string& reason) {
  1045. const char* type = "ws_getvar";
  1046. Json::Value log;
  1047. log["hdl"] = Json::Int64(hdl);
  1048. log["78173721_logType"] = type;
  1049. m_logTotal[hdl][type].num += 1;
  1050. Json::Value detail;
  1051. detail["web_transID"] = Json::Int64(web_transID);
  1052. detail["inner_transID"] = Json::Int64(inner_transID);
  1053. detail["name"] = name;
  1054. detail["ret"] = ret;
  1055. detail["operate"] = operate;
  1056. detail["retDetail"] = retDetail;
  1057. detail["reason"] = reason;
  1058. #ifdef OUTPUT_DETAIL_LOG
  1059. detail["payload"] = payload;
  1060. #endif
  1061. log["detail"] = detail;
  1062. log["timestamp"] = getCurrentTimestamp();
  1063. if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
  1064. log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
  1065. log["threadId"] = Json::Int64(GetCurrentThreadId());
  1066. writeLog(LOG_LEVEL_DEBUG, log);
  1067. }
  1068. void LogManager::logWebSocketBroadcast(int64_t hdl,
  1069. const std::string& entity,
  1070. int ret,
  1071. const std::string& operate,
  1072. const std::string& payload,
  1073. int retDetail,
  1074. const std::string& reason) {
  1075. const char* type = "ws_broadcast";
  1076. Json::Value log;
  1077. log["hdl"] = Json::Int64(hdl);
  1078. log["78173721_logType"] = type;
  1079. m_logTotal[hdl][type].num += 1;
  1080. Json::Value detail;
  1081. detail["entity"] = entity;
  1082. detail["ret"] = ret;
  1083. detail["operate"] = operate;
  1084. detail["retDetail"] = retDetail;
  1085. detail["reason"] = reason;
  1086. #ifdef OUTPUT_DETAIL_LOG
  1087. detail["payload"] = payload;
  1088. #endif
  1089. log["detail"] = detail;
  1090. log["timestamp"] = getCurrentTimestamp();
  1091. if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
  1092. log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
  1093. log["threadId"] = Json::Int64(GetCurrentThreadId());
  1094. writeLog(LOG_LEVEL_DEBUG, log);
  1095. }
  1096. void LogManager::logVtmEndSession(int64_t hdl,
  1097. const std::string& entity,
  1098. int64_t sessionId,
  1099. int ret,
  1100. const std::string& operate,
  1101. const std::string& payload,
  1102. int retDetail,
  1103. const std::string& reason) {
  1104. const char* type = "vtm_endsession";
  1105. Json::Value log;
  1106. log["hdl"] = Json::Int64(hdl);
  1107. log["78173721_logType"] = type;
  1108. m_logTotal[hdl][type].num += 1;
  1109. Json::Value detail;
  1110. detail["entity"] = entity;
  1111. detail["sessionId"] = Json::Int64(sessionId);
  1112. detail["ret"] = ret;
  1113. detail["operate"] = operate;
  1114. detail["retDetail"] = retDetail;
  1115. detail["reason"] = reason;
  1116. #ifdef OUTPUT_DETAIL_LOG
  1117. detail["payload"] = payload;
  1118. #endif
  1119. log["detail"] = detail;
  1120. log["timestamp"] = getCurrentTimestamp();
  1121. if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
  1122. log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
  1123. log["threadId"] = Json::Int64(GetCurrentThreadId());
  1124. writeLog(LOG_LEVEL_DEBUG, log);
  1125. }
  1126. void LogManager::logVtmRequestAck(int64_t hdl,
  1127. int64_t web_transID,
  1128. int64_t inner_transID,
  1129. int64_t sessionId,
  1130. const std::string& entity,
  1131. const std::string& function,
  1132. int ret,
  1133. const std::string& operate,
  1134. const std::string& payload,
  1135. const std::string& srcByte,
  1136. int retDetail,
  1137. const std::string& reason) {
  1138. const char* type = "vtm_requestAck";
  1139. Json::Value log;
  1140. log["hdl"] = Json::Int64(hdl);
  1141. log["78173721_logType"] = type;
  1142. m_logTotal[hdl][type].num += 1;
  1143. Json::Value detail;
  1144. detail["web_transID"] = Json::Int64(web_transID);
  1145. detail["inner_transID"] = Json::Int64(inner_transID);
  1146. detail["sessionId"] = Json::Int64(sessionId);
  1147. detail["entity"] = entity;
  1148. detail["function"] = function;
  1149. detail["ret"] = ret;
  1150. detail["operate"] = operate;
  1151. #ifdef OUTPUT_DETAIL_LOG
  1152. detail["payload"] = payload;
  1153. detail["srcByte"] = srcByte;
  1154. #endif
  1155. detail["retDetail"] = retDetail;
  1156. detail["reason"] = reason;
  1157. log["detail"] = detail;
  1158. log["timestamp"] = getCurrentTimestamp();
  1159. if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
  1160. log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
  1161. log["threadId"] = Json::Int64(GetCurrentThreadId());
  1162. writeLog(LOG_LEVEL_DEBUG, log);
  1163. }
  1164. void LogManager::logVtmEvent(int64_t hdl,
  1165. int64_t inner_transID,
  1166. int64_t sessionId,
  1167. const std::string& entity,
  1168. int ret,
  1169. const std::string& operate,
  1170. const std::vector<std::pair<int, int>>& transIdAndhdl_arr,
  1171. const std::string& payload,
  1172. const std::string& srcByte,
  1173. int retDetail,
  1174. const std::string& reason) {
  1175. const char* type = "vtm_event";
  1176. Json::Value log;
  1177. log["hdl"] = Json::Int64(hdl);
  1178. log["78173721_logType"] = type;
  1179. m_logTotal[hdl][type].num += 1;
  1180. Json::Value detail;
  1181. detail["inner_transID"] = Json::Int64(inner_transID);
  1182. detail["sessionId"] = Json::Int64(sessionId);
  1183. detail["entity"] = entity;
  1184. detail["ret"] = ret;
  1185. detail["operate"] = operate;
  1186. Json::Value transIdAndhdl_json(Json::arrayValue);
  1187. for (const auto& pair : transIdAndhdl_arr) {
  1188. Json::Value pairJson(Json::objectValue);
  1189. pairJson["transId"] = Json::Int64(pair.first);
  1190. pairJson["hdl"] = Json::Int64(pair.second);
  1191. transIdAndhdl_json.append(pairJson);
  1192. }
  1193. detail["transIdAndhdl_arr"] = transIdAndhdl_json;
  1194. #ifdef OUTPUT_DETAIL_LOG
  1195. detail["payload"] = payload;
  1196. detail["srcByte"] = srcByte;
  1197. #endif
  1198. detail["retDetail"] = retDetail;
  1199. detail["reason"] = reason;
  1200. log["detail"] = detail;
  1201. log["timestamp"] = getCurrentTimestamp();
  1202. if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
  1203. log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
  1204. log["threadId"] = Json::Int64(GetCurrentThreadId());
  1205. writeLog(LOG_LEVEL_DEBUG, log);
  1206. }
  1207. void LogManager::logVtmSessionAck(int64_t hdl,
  1208. int64_t web_transID,
  1209. int64_t inner_transID,
  1210. int64_t sessionId,
  1211. const std::string& entity,
  1212. int ret,
  1213. const std::string& operate,
  1214. const std::string& payload,
  1215. const std::string& srcByte,
  1216. int retDetail,
  1217. const std::string& reason) {
  1218. const char* type = "vtm_sessionAck";
  1219. Json::Value log;
  1220. log["hdl"] = Json::Int64(hdl);
  1221. log["78173721_logType"] = type;
  1222. m_logTotal[hdl][type].num += 1;
  1223. Json::Value detail;
  1224. detail["web_transID"] = Json::Int64(web_transID);
  1225. detail["inner_transID"] = Json::Int64(inner_transID);
  1226. detail["sessionId"] = Json::Int64(sessionId);
  1227. detail["entity"] = entity;
  1228. detail["ret"] = ret;
  1229. detail["operate"] = operate;
  1230. #ifdef OUTPUT_DETAIL_LOG
  1231. detail["payload"] = payload;
  1232. detail["srcByte"] = srcByte;
  1233. #endif
  1234. detail["retDetail"] = retDetail;
  1235. detail["reason"] = reason;
  1236. log["detail"] = detail;
  1237. log["timestamp"] = getCurrentTimestamp();
  1238. if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
  1239. log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
  1240. log["threadId"] = Json::Int64(GetCurrentThreadId());
  1241. writeLog(LOG_LEVEL_DEBUG, log);
  1242. }
  1243. void LogManager::logWsLogEvent(
  1244. int64_t hdl,
  1245. int securityLevel,
  1246. int eventCode,
  1247. const std::string& message,
  1248. int ret,
  1249. const std::string& operate,
  1250. const std::string& payload,
  1251. int retDetail,
  1252. const std::string& reason
  1253. ) {
  1254. const char* type = "ws_logEvent";
  1255. Json::Value log;
  1256. log["hdl"] = Json::Int64(hdl);
  1257. log["78173721_logType"] = type;
  1258. m_logTotal[hdl][type].num += 1;
  1259. Json::Value detail;
  1260. detail["securityLevel"] = securityLevel;
  1261. detail["eventCode"] = eventCode;
  1262. detail["message"] = message;
  1263. detail["ret"] = ret;
  1264. detail["operate"] = operate;
  1265. detail["retDetail"] = retDetail;
  1266. detail["reason"] = reason;
  1267. #ifdef OUTPUT_DETAIL_LOG
  1268. detail["payload"] = payload;
  1269. #endif
  1270. log["detail"] = detail;
  1271. log["timestamp"] = getCurrentTimestamp();
  1272. if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
  1273. log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
  1274. log["threadId"] = Json::Int64(GetCurrentThreadId());
  1275. writeLog(LOG_LEVEL_DEBUG, log);
  1276. }
  1277. void LogManager::logWsLogWarn(
  1278. int64_t hdl,
  1279. int securityLevel,
  1280. int eventCode,
  1281. const std::string& message,
  1282. int ret,
  1283. const std::string& operate,
  1284. const std::string& payload,
  1285. int retDetail,
  1286. const std::string& reason
  1287. ) {
  1288. const char* type = "ws_logWarn";
  1289. Json::Value log;
  1290. log["hdl"] = Json::Int64(hdl);
  1291. log["78173721_logType"] = type;
  1292. m_logTotal[hdl][type].num += 1;
  1293. Json::Value detail;
  1294. detail["securityLevel"] = securityLevel;
  1295. detail["eventCode"] = eventCode;
  1296. detail["ret"] = ret;
  1297. detail["operate"] = operate;
  1298. detail["retDetail"] = retDetail;
  1299. detail["reason"] = reason;
  1300. #ifdef OUTPUT_DETAIL_LOG
  1301. detail["payload"] = payload;
  1302. detail["message"] = message;
  1303. #endif
  1304. log["detail"] = detail;
  1305. log["timestamp"] = getCurrentTimestamp();
  1306. if (ConfigManager::getInstance().m_ws_infoArr.find(hdl) != ConfigManager::getInstance().m_ws_infoArr.end())//add websocket label
  1307. log["name"] = ConfigManager::getInstance().m_ws_infoArr[hdl].name;
  1308. log["threadId"] = Json::Int64(GetCurrentThreadId());
  1309. writeLog(LOG_LEVEL_DEBUG, log);
  1310. }
  1311. void LogManager::logEntityOnLog(
  1312. const std::string& entity,
  1313. int64_t usercode,
  1314. const std::string& usercodeStr,
  1315. int ret,
  1316. const std::string& operate,
  1317. int retDetail,
  1318. const std::string& reason
  1319. ) {
  1320. Json::Value log;
  1321. log["78173721_logType"] = "entity_onlog";
  1322. Json::Value detail;
  1323. detail["entity"] = entity;
  1324. detail["usercode"] = Json::Int64(usercode);
  1325. detail["usercodeStr"] = usercodeStr;
  1326. detail["ret"] = ret;
  1327. detail["operate"] = operate;
  1328. detail["retDetail"] = retDetail;
  1329. detail["reason"] = reason;
  1330. log["detail"] = detail;
  1331. log["timestamp"] = getCurrentTimestamp();
  1332. log["threadId"] = Json::Int64(GetCurrentThreadId());
  1333. writeLog(LOG_LEVEL_INFO, log);
  1334. }
  1335. void LogManager::logEntityBegin(int no_startup) {
  1336. Json::Value log;
  1337. log["78173721_logType"] = "entity_begin";
  1338. Json::Value detail;
  1339. detail["no_startup"] = no_startup;
  1340. log["detail"] = detail;
  1341. log["threadId"] = Json::Int64(GetCurrentThreadId());
  1342. log["timestamp"] = getCurrentTimestamp();
  1343. writeLog(LOG_LEVEL_INFO, log);
  1344. }
  1345. void LogManager::logEntityOpenPage(
  1346. const std::string& pageType,
  1347. int64_t pid,
  1348. int ret,
  1349. const std::string& operate,
  1350. int retDetail,
  1351. const std::string& reason
  1352. ) {
  1353. Json::Value log;
  1354. log["78173721_logType"] = "entity_openPage";
  1355. Json::Value detail;
  1356. detail["pageType"] = pageType;
  1357. detail["pid"] = Json::Int64(pid);
  1358. detail["ret"] = ret;
  1359. detail["operate"] = operate;
  1360. detail["retDetail"] = retDetail;
  1361. detail["reason"] = reason;
  1362. log["detail"] = detail;
  1363. log["threadId"] = Json::Int64(GetCurrentThreadId());
  1364. log["timestamp"] = getCurrentTimestamp();
  1365. writeLog(LOG_LEVEL_INFO, log);
  1366. }
  1367. void LogManager::logEntityStageChange(
  1368. const std::string& stage,
  1369. int ret,
  1370. const std::string& operate,
  1371. int retDetail,
  1372. const std::string& reason
  1373. ) {
  1374. Json::Value log;
  1375. log["78173721_logType"] = "entity_stageChange";
  1376. Json::Value detail;
  1377. detail["stage"] = stage;
  1378. detail["ret"] = ret;
  1379. detail["operate"] = operate;
  1380. detail["retDetail"] = retDetail;
  1381. detail["reason"] = reason;
  1382. log["detail"] = detail;
  1383. log["threadId"] = Json::Int64(GetCurrentThreadId());
  1384. log["timestamp"] = getCurrentTimestamp();
  1385. writeLog(LOG_LEVEL_INFO, log);
  1386. }
  1387. void LogManager::logEntityStatus(
  1388. const std::string& status,
  1389. int level,
  1390. int ret,
  1391. const std::string& operate,
  1392. int retDetail,
  1393. const std::string& reason
  1394. ) {
  1395. Json::Value log;
  1396. log["78173721_logType"] = "entity_status";
  1397. Json::Value detail;
  1398. detail["status"] = status;
  1399. detail["level"] = level;
  1400. detail["ret"] = ret;
  1401. detail["operate"] = operate;
  1402. detail["retDetail"] = retDetail;
  1403. detail["reason"] = reason;
  1404. log["detail"] = detail;
  1405. log["threadId"] = Json::Int64(GetCurrentThreadId());
  1406. log["timestamp"] = getCurrentTimestamp();
  1407. writeLog(LOG_LEVEL_INFO, log);
  1408. }