Browse Source

#IQRV #comment 支持本地落地开关和运行

80374374 1 year ago
parent
commit
f1e620fcfd

+ 88 - 0
Module/include/CommEntitySettings.hpp

@@ -104,6 +104,94 @@ static inline ErrorCodeEnum ReadConfigFromCenterSettings(
     return result;
 }
 
+static inline void InitializeOtherLogSwitch(CEntityBase* pEntity, const CSimpleStringA& strModuleName)
+{
+	LOG_FUNCTION();
+	if (pEntity == NULL || strModuleName.IsNullOrEmpty()) {
+		return;
+	}
+
+	struct OtherLogConfig
+	{
+		OtherLogConfig() :strLevel("OFF"), strType("FILE"), strDllName(""), strLogPath("") {}
+		OtherLogConfig(const CSimpleStringA& strModuleName) :strLevel("OFF"), strType("FILE"), strDllName(strModuleName), strLogPath("") {}
+
+		CSimpleStringA strLevel;
+		CSimpleStringA strType;
+		CSimpleStringA strDllName;
+		CSimpleStringA strLogPath;
+
+		void Settle()
+		{
+			toolkit_setenv("VENDOR_RECODE_LEVEL", strLevel);
+			toolkit_setenv("VENDOR_RECODE_TYPE", strType);
+			toolkit_setenv("VENDOR_DLL_NAME", strDllName);
+			toolkit_setenv("VENDOR_LOG_PATH", strLogPath);
+		}
+
+	} stLogConfig(strModuleName);
+
+	CSmartPointer<IConfigInfo> centerConfig;
+	pEntity->GetFunction()->OpenConfig(Config_CenterSetting, centerConfig);
+
+	int nSaveFileOrNot(0);
+
+	centerConfig->ReadConfigValueInt("Common", "SaveFile", nSaveFileOrNot);
+	stLogConfig.strType = "UPLOAD";
+	if ((nSaveFileOrNot & 1) == 1) {
+		if (!stLogConfig.strType.IsNullOrEmpty()) stLogConfig.strType += "|";
+		stLogConfig.strType += "FILE";
+	}
+
+	int nUploadLogLevel(1); /*INFO*/
+
+	CSimpleStringA strUploadLogLevelEntity(true);
+	centerConfig->ReadConfigValue(strModuleName.GetData(), "UpLoadLogLevel", strUploadLogLevelEntity);
+	if (strUploadLogLevelEntity.IsNullOrEmpty()) {
+		CSimpleStringA strUploadLogLevelComm(true);
+		centerConfig->ReadConfigValue("Common", "UpLoadLogLevel", strUploadLogLevelComm);
+		strUploadLogLevelEntity = strUploadLogLevelComm;
+	}
+	bool isValidDigit = !strUploadLogLevelEntity.IsNullOrEmpty();
+	for (int i = 0; i < strUploadLogLevelEntity.GetLength(); ++i) {
+		if (!(strUploadLogLevelEntity[i] >= '0' && strUploadLogLevelEntity[i] <= '9')) {
+			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("invalid param: %s", strUploadLogLevelEntity.GetData());
+			isValidDigit = false;
+			break;
+		}
+	}
+	if (isValidDigit) {
+		nUploadLogLevel = atoi(strUploadLogLevelEntity.GetData());
+	}
+	switch (nUploadLogLevel)
+	{
+	case 0: /*LOG_LEVEL_DEBUG*/
+		stLogConfig.strLevel = "ALL";
+		break;
+	case 1: /*LOG_LEVEL_INFO*/
+		stLogConfig.strLevel = "INFO";
+		break;
+	case 2: /*LOG_LEVEL_WARN*/
+		stLogConfig.strLevel = "WARN";
+		break;
+	case 3: /*LOG_LEVEL_ERROR*/
+		stLogConfig.strLevel = "ERROR";
+		break;
+	case 4: /*LOG_LEVEL_FATAL*/
+		stLogConfig.strLevel = "FATAL";
+		break;
+	default:
+		stLogConfig.strLevel = "OFF";
+		break;
+	}
+
+	pEntity->GetFunction()->GetPath("Dbg", stLogConfig.strLogPath);
+	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("DbgPath: %s", stLogConfig.strLogPath.GetData());
+	stLogConfig.Settle();
+
+	LogEvent(Severity_Low, 0, CSimpleStringA::Format("{\"RecordLevel\":\"%s\", \"RecordType\":\"%s\}", stLogConfig.strLevel.GetData(), stLogConfig.strType.GetData()));
+}
+
 
 } //namespace Settings
 } //namespace Comm

+ 4 - 1
Module/mod_healthmanager/mod_healthmanager.cpp

@@ -48,6 +48,7 @@ using namespace std;
 
 #include "mod_healthmanager.h"
 #include "CommEntityUtil.hpp"
+#include "CommEntitySettings.hpp"
 #include "GetDevInfoHelper.h"
 #include "TerminalInfoQueryConn.h"
 
@@ -900,6 +901,8 @@ bool CHealthManagerEntity::StartGuardian()
 	//oiltmp TODO 如果是未安装,不启动guardian
 	//root.ini 不存在,表示未安装
 
+	/** 添加日志控制逻辑 Gifur@202414]*/
+	SP::Module::Comm::Settings::InitializeOtherLogSwitch(this, "guardian");
 	DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("StartGuardian")("启动 to start guardian");
 	// Start the child process.
 	CSimpleStringA csBinPath, csAll, csSep("\"");
@@ -929,7 +932,7 @@ bool CHealthManagerEntity::StartGuardian()
 	DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("StartGuardian")("guardian path[%s]",(LPCTSTR)csBinPath);
 	csAll = csSep +  csBinPath + csSep;
 	LPTSTR szCmdline = _strdup(csAll);
-	if( !CreateProcess( NULL,szCmdline,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi)) 
+	if( !CreateProcessA( NULL,szCmdline,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi)) 
 	{
 		DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI("StartGuardian")("CreateProcess failed (%d).\n", GetLastError());
 		return false;

+ 4 - 2
Other/liblog4rvcother/liblog4rvcother.cpp

@@ -15,7 +15,9 @@ static HMODULE gModule = NULL;
 #include <unistd.h>
 #define CUR_PROCESS_NAME "sphost"
 #endif
-static int IsSphostExe = -1;
+
+//该版本默认为TRUE
+static int IsSphostExe = TRUE;
 
 BOOL GetCurProcessPath(char szPath[], DWORD dwPathSize);
 
@@ -67,7 +69,7 @@ EXTERN_C BOOL GetCurFileVersion(char szVerion[], DWORD dwVerionSize)
 		(pFinfo->dwFileVersionLS) & 0xFF);
 
 #endif
-
+	sprintf(szVerion, "1.0.0.0");
 	return TRUE;
 }
 

+ 100 - 0
Other/liblog4rvcother/liblog4rvcother.rc

@@ -0,0 +1,100 @@
+// Microsoft Visual C++ generated resource script.
+//
+#include "resource.h"
+
+#define APSTUDIO_READONLY_SYMBOLS
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 2 resource.
+//
+#include "winres.h"
+
+/////////////////////////////////////////////////////////////////////////////
+#undef APSTUDIO_READONLY_SYMBOLS
+
+/////////////////////////////////////////////////////////////////////////////
+// 中文(简体,中国) resources
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
+LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED
+#pragma code_page(936)
+
+#ifdef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// TEXTINCLUDE
+//
+
+1 TEXTINCLUDE 
+BEGIN
+    "resource.h\0"
+END
+
+2 TEXTINCLUDE 
+BEGIN
+    "#include ""winres.h""\r\n"
+    "\0"
+END
+
+3 TEXTINCLUDE 
+BEGIN
+    "\r\n"
+    "\0"
+END
+
+#endif    // APSTUDIO_INVOKED
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Version
+//
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION 1,0,0,1
+ PRODUCTVERSION 1,0,0,1
+ FILEFLAGSMASK 0x3fL
+#ifdef _DEBUG
+ FILEFLAGS 0x1L
+#else
+ FILEFLAGS 0x0L
+#endif
+ FILEOS 0x40004L
+ FILETYPE 0x2L
+ FILESUBTYPE 0x0L
+BEGIN
+    BLOCK "StringFileInfo"
+    BEGIN
+        BLOCK "080404b0"
+        BEGIN
+            VALUE "CompanyName", "cmb"
+            VALUE "FileDescription", "cmb"
+            VALUE "FileVersion", "1.0.0.1"
+            VALUE "InternalName", "liblog4rvcother.dll"
+            VALUE "LegalCopyright", "Copyright (C) 2024"
+            VALUE "OriginalFilename", "liblog4rvcother.dll"
+            VALUE "ProductName", "log for rvc terminal"
+            VALUE "ProductVersion", "1.0.0.1"
+        END
+    END
+    BLOCK "VarFileInfo"
+    BEGIN
+        VALUE "Translation", 0x804, 1200
+    END
+END
+
+#endif    // 中文(简体,中国) resources
+/////////////////////////////////////////////////////////////////////////////
+
+
+
+#ifndef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 3 resource.
+//
+
+
+/////////////////////////////////////////////////////////////////////////////
+#endif    // not APSTUDIO_INVOKED
+

+ 1 - 1
Other/liblog4rvcother/log4cplus_helper.cpp

@@ -68,7 +68,7 @@ namespace cmb {
 		:_append_console(NULL),_append_file(NULL),_append_socket(NULL),_append_none(NULL)
 		,_socket_send_running(false)
 	    ,_initialized(false),_append_type(0),_log_server_port(0),_log_listen_port(0)
-		,_initilzed_zip(false),_cur_upload_log(""),_cur_upload_offset(0),_log_level(NOT_SET_LOG_LEVEL)
+		,_initilzed_zip(false),_cur_upload_log(""),_cur_upload_offset(0),_log_level(NOT_SET_LOG_LEVEL), _initialize_uploaded(false)
 	{
 		_log_dir.clear();
 		_log_server_ip.clear();

+ 1 - 0
Other/liblog4rvcother/log4cplus_helper.h

@@ -175,6 +175,7 @@ namespace cmb {
 
 		int _log_level;
 
+		bool _initialize_uploaded;
 		upload_helper _upload_helper;
 	};
 }

+ 5 - 1
Other/liblog4rvcother/log4rvcother.cpp

@@ -87,6 +87,8 @@ namespace cmb {
 		const std::string record_type = toupper(env.record_type);
 		if(record_type.find("FILE") != std::string::npos)
 			config->log_type |= CMB_LOG_TYPE_FILE;
+		if (record_type.find("UPLOAD") != std::string::npos)
+			config->log_type |= CMB_LOG_TYPE_SOCKET;
 
 		/*get log level*/
 		const std::string record_level = toupper(env.record_level);
@@ -121,6 +123,8 @@ namespace cmb {
                 config->dev_name += lib_name;
             }
 #endif //_MSC_VER
+		} else {
+			config->dev_name = env.module_name;
 		}
 		config->log_dir = env.record_path;
 	}
@@ -205,7 +209,7 @@ namespace cmb {
 
 		/*提前在这里赋值,以便让 LOG4VTM 宏生效*/
 		log4plus_initialized = true;
-        if (is_vtm_env) {
+        if (is_vtm_env && (lhs->log_type & CMB_LOG_TYPE_SOCKET) != 0) {
             log4cplus_helper::get_instance()->initialize_linklog(*lhs);
         }
 		LOG4VTM(INFO, "==============Log4Vendor(" << instance_name << ") start==============");

+ 1 - 0
Other/liblog4rvcother/log4rvcother.h

@@ -12,6 +12,7 @@
 #define LOG4RVCOTHER_API __declspec(dllexport)
 #else
 #define LOG4RVCOTHER_API __declspec(dllimport)
+#pragma comment(lib, "liblog4rvcother.lib")
 #endif
 #else
 #if ( defined(__GNUC__) &&  __GNUC__ >= 4 )

+ 1 - 1
Tool/guardian/guardian.cpp

@@ -1074,7 +1074,7 @@ void DataProcess(LPPER_HANDLE_DATA pPerHandleData,LPPER_IO_OPERATION_DATA pPerIo
 			if (pInfo->dwParam1 == 1 || pInfo->dwParam1 == 3)
 				g_dwTimeBegin = GetTickCountRVC();
 			ServerReportEvent("upgrade restart");
-			LOG4VTM(INFO << "upgrade restart " << pInfo->dwParam1);
+			LOG4VTM(INFO, "upgrade restart " << pInfo->dwParam1);
 			if (pInfo->dwParam1 == 1)//framework to restart after upgrade
 			{
 				g_bInUpgrade = true;