log_module.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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_TOTLA; 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_TOTLA)
  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. //vtLog[fileType]->WriteLog(content);
  40. return 0;
  41. }
  42. int Log::write_log(FILE_TYPE fileType,const char* pValue,bool status)
  43. {
  44. if (fileType > FILE_TYPE::FILE_TYPE_TOTLA)
  45. {
  46. return 1;
  47. }
  48. if (vtLog.size() < fileType)
  49. {
  50. return 1;
  51. }
  52. if (status != vtLog[fileType]->GetStatus())
  53. {
  54. vtLog[fileType]->SetLayout(status);
  55. }
  56. write_log(fileType,pValue);
  57. return 0;
  58. }
  59. int Log::write_log(FILE_TYPE fileType,const char* pValue)
  60. {
  61. std::string val = "";
  62. val = pValue;
  63. write_log(fileType,val);
  64. return 0;
  65. }
  66. //int Log::write_log(FILE_TYPE fileType,const char* pValue,...)
  67. //{
  68. // std::string val = "";
  69. // val = pValue;
  70. //
  71. // write_log(fileType,val);
  72. //
  73. // return 0;
  74. //}
  75. int Log::write_log(FILE_TYPE fileType,const std::string& content,bool status)
  76. {
  77. if (fileType > FILE_TYPE::FILE_TYPE_TOTLA)
  78. {
  79. return 1;
  80. }
  81. if (vtLog.size() < fileType)
  82. {
  83. return 1;
  84. }
  85. if (status != vtLog[fileType]->GetStatus())
  86. {
  87. vtLog[fileType]->SetLayout(status);
  88. }
  89. write_log(fileType,content);
  90. return 0;
  91. }
  92. int Log::clear()
  93. {
  94. if (vtLog.size() > 0)
  95. {
  96. vtLog.erase(vtLog.begin(),vtLog.end());
  97. vtLog.resize(0);
  98. }
  99. if (mpLog.size() > 0)
  100. {
  101. mpLog.erase(mpLog.begin(),mpLog.end());
  102. }
  103. return 0;
  104. }