CommEntitySettings.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #ifndef RVC_MOD_COMM_ENTITY_SETTINGS_HPP_
  2. #define RVC_MOD_COMM_ENTITY_SETTINGS_HPP_
  3. #include "SpBase.h"
  4. #include "fileutil.h"
  5. namespace SP
  6. {
  7. namespace Module
  8. {
  9. namespace Comm
  10. {
  11. namespace Settings
  12. {
  13. static inline void InitializeOtherLogSwitch(CEntityBase* pEntity, const CSimpleStringA& strModuleName)
  14. {
  15. LOG_FUNCTION();
  16. if (pEntity == NULL || strModuleName.IsNullOrEmpty()) {
  17. return;
  18. }
  19. struct OtherLogConfig
  20. {
  21. OtherLogConfig() :strLevel("OFF"), strType("FILE"), strDllName(""), strLogPath("") {}
  22. OtherLogConfig(const CSimpleStringA& strModuleName) :strLevel("OFF"), strType("FILE"), strDllName(strModuleName), strLogPath("") {}
  23. CSimpleStringA strLevel;
  24. CSimpleStringA strType;
  25. CSimpleStringA strDllName;
  26. CSimpleStringA strLogPath;
  27. void Settle()
  28. {
  29. toolkit_setenv("VENDOR_RECODE_LEVEL", strLevel);
  30. toolkit_setenv("VENDOR_RECODE_TYPE", strType);
  31. toolkit_setenv("VENDOR_DLL_NAME", strDllName);
  32. toolkit_setenv("VENDOR_LOG_PATH", strLogPath);
  33. }
  34. } stLogConfig(strModuleName);
  35. CSmartPointer<IConfigInfo> centerConfig;
  36. pEntity->GetFunction()->OpenConfig(Config_CenterSetting, centerConfig);
  37. int nSaveFileOrNot(0);
  38. centerConfig->ReadConfigValueInt("Common", "SaveFile", nSaveFileOrNot);
  39. stLogConfig.strType = "UPLOAD";
  40. if ((nSaveFileOrNot & 1) == 1) {
  41. if (!stLogConfig.strType.IsNullOrEmpty()) stLogConfig.strType += "|";
  42. stLogConfig.strType += "FILE";
  43. }
  44. int nUploadLogLevel(1); /*INFO*/
  45. CSimpleStringA strUploadLogLevelEntity(true);
  46. centerConfig->ReadConfigValue(strModuleName.GetData(), "UpLoadLogLevel", strUploadLogLevelEntity);
  47. if (strUploadLogLevelEntity.IsNullOrEmpty()) {
  48. CSimpleStringA strUploadLogLevelComm(true);
  49. centerConfig->ReadConfigValue("Common", "UpLoadLogLevel", strUploadLogLevelComm);
  50. strUploadLogLevelEntity = strUploadLogLevelComm;
  51. }
  52. bool isValidDigit = !strUploadLogLevelEntity.IsNullOrEmpty();
  53. for (int i = 0; i < strUploadLogLevelEntity.GetLength(); ++i) {
  54. if (!(strUploadLogLevelEntity[i] >= '0' && strUploadLogLevelEntity[i] <= '9')) {
  55. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("invalid param: %s", strUploadLogLevelEntity.GetData());
  56. isValidDigit = false;
  57. break;
  58. }
  59. }
  60. if (isValidDigit) {
  61. nUploadLogLevel = atoi(strUploadLogLevelEntity.GetData());
  62. }
  63. switch (nUploadLogLevel)
  64. {
  65. case 0: /*LOG_LEVEL_DEBUG*/
  66. stLogConfig.strLevel = "ALL";
  67. break;
  68. case 1: /*LOG_LEVEL_INFO*/
  69. stLogConfig.strLevel = "INFO";
  70. break;
  71. case 2: /*LOG_LEVEL_WARN*/
  72. stLogConfig.strLevel = "WARN";
  73. break;
  74. case 3: /*LOG_LEVEL_ERROR*/
  75. stLogConfig.strLevel = "ERROR";
  76. break;
  77. case 4: /*LOG_LEVEL_FATAL*/
  78. stLogConfig.strLevel = "FATAL";
  79. break;
  80. default:
  81. stLogConfig.strLevel = "OFF";
  82. break;
  83. }
  84. pEntity->GetFunction()->GetPath("Dbg", stLogConfig.strLogPath);
  85. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("DbgPath: %s", stLogConfig.strLogPath.GetData());
  86. stLogConfig.Settle();
  87. LogEvent(Severity_Low, 0, CSimpleStringA::Format("{\"RecordLevel\":\"%s\", \"RecordType\":\"%s\}", stLogConfig.strLevel.GetData(), stLogConfig.strType.GetData()));
  88. }
  89. } //namespace Settings
  90. } //namespace Comm
  91. } //namespace Module
  92. } //SP
  93. #endif //RVC_MOD_COMM_ENTITY_SETTINGS_HPP_