log_module.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #include "stdafx.h"
  2. #include "log_module.h"
  3. #include "Functions/Functions.h"
  4. std::vector<std::shared_ptr<MyLog>> vtLog;
  5. std::map<std::string,std::shared_ptr<MyLog>> mpLog;
  6. int Log::init_log_module()
  7. {
  8. clear();
  9. for (int i = 0; i < FILE_TYPE_TOTAL; i++)
  10. {
  11. std::shared_ptr<MyLog> log = std::make_shared<MyLog>((FILE_TYPE)i);
  12. vtLog.push_back(log);
  13. //mpLog.insert(std::make_pair(my_log_file_name[i],log));
  14. }
  15. return 0;
  16. }
  17. int Log::write_log(FILE_TYPE fileType,const std::string& content)
  18. {
  19. if (fileType > FILE_TYPE::FILE_TYPE_TOTAL)
  20. {
  21. return 1;
  22. }
  23. if (vtLog.size() < fileType)
  24. {
  25. return 1;
  26. }
  27. std::vector<std::shared_ptr<MyLog>>::iterator it = vtLog.begin();
  28. for (;it != vtLog.end();++it)
  29. {
  30. if ((*it)->GetFileType() == fileType)
  31. {
  32. break;
  33. }
  34. }
  35. if (it != vtLog.end())
  36. {
  37. (*it)->WriteLog(content);
  38. }
  39. return 0;
  40. }
  41. int Log::write_log(FILE_TYPE fileType,const char* pValue,bool status)
  42. {
  43. if (fileType > FILE_TYPE::FILE_TYPE_TOTAL)
  44. {
  45. return 1;
  46. }
  47. if (vtLog.size() < fileType)
  48. {
  49. return 1;
  50. }
  51. if (status != vtLog[fileType]->GetStatus())
  52. {
  53. vtLog[fileType]->SetLayout(status);
  54. }
  55. write_log(fileType,pValue);
  56. return 0;
  57. }
  58. int Log::write_log(FILE_TYPE fileType,const char* pValue)
  59. {
  60. std::string val = "";
  61. val = pValue;
  62. write_log(fileType,val);
  63. return 0;
  64. }
  65. //int Log::write_log(FILE_TYPE fileType,const char* pValue,...)
  66. //{
  67. // std::string val = "";
  68. // val = pValue;
  69. //
  70. // write_log(fileType,val);
  71. //
  72. // return 0;
  73. //}
  74. int Log::write_log(FILE_TYPE fileType,const std::string& content,bool status)
  75. {
  76. if (fileType > FILE_TYPE::FILE_TYPE_TOTAL)
  77. {
  78. return 1;
  79. }
  80. if (vtLog.size() < fileType)
  81. {
  82. return 1;
  83. }
  84. if (status != vtLog[fileType]->GetStatus())
  85. {
  86. vtLog[fileType]->SetLayout(status);
  87. }
  88. write_log(fileType,content);
  89. return 0;
  90. }
  91. int Log::clear()
  92. {
  93. if (vtLog.size() > 0)
  94. {
  95. vtLog.erase(vtLog.begin(),vtLog.end());
  96. vtLog.resize(0);
  97. }
  98. if (mpLog.size() > 0)
  99. {
  100. mpLog.erase(mpLog.begin(),mpLog.end());
  101. }
  102. return 0;
  103. }