123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- #ifndef RVC_MOD_COMM_ENTITY_SETTINGS_HPP_
- #define RVC_MOD_COMM_ENTITY_SETTINGS_HPP_
- #include "SpBase.h"
- #include "fileutil.h"
- namespace SP
- {
- namespace Module
- {
- namespace Comm
- {
- namespace Settings
- {
- 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
- } //namespace Module
- } //SP
- #endif //RVC_MOD_COMM_ENTITY_SETTINGS_HPP_
|