You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
3.4 KiB

7 years ago
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
7 years ago
7 years ago
​
7 years ago
7 years ago
​
​
​
7 years ago
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
7 years ago
​
​
​
  1. #include "basicLogCollection.h"
  2. #ifdef MEM_DEBUG_LOG
  3. #include "../../alg/generic/heapDebug.h"
  4. #endif
  5. basicLogCollection * basicLogCollection::_instance = 0;
  6. /**
  7. * Returns the single instance of the object.
  8. */
  9. basicLogCollection * basicLogCollection::getInstance(_LOG_SETTINGS val)
  10. {
  11. // check if the instance has been created yet
  12. if (0 == _instance)
  13. {
  14. // if not, then create it
  15. _instance = new basicLogCollection(val);
  16. };
  17. // return the single instance
  18. return _instance;
  19. }
  20. void basicLogCollection::addHandler(basicLoggingService * handler)
  21. {
  22. if (m_pRing != NULL)
  23. {
  24. m_pRing->add(handler);
  25. }
  26. }
  27. void basicLogCollection::broadcast(CSTR Msg)
  28. {
  29. basicLoggingService * mService;
  30. LoggersIterator * mpIterator;
  31. m_pLogMutex->lock();
  32. mpIterator = m_pRing->begin();
  33. while (mpIterator != NULL)
  34. {
  35. mService = m_pRing->getAtCursor(mpIterator);
  36. mService->logMessage(Msg);
  37. mpIterator = mpIterator->next;
  38. };
  39. m_pLogMutex->unlock();
  40. }
  41. void basicLogCollection::setLogLevel(_LOG_LEVEL level)
  42. {
  43. m_bMaxLevel = level;
  44. }
  45. void basicLogCollection::Log(const char * Mod, void * ptr, CSTR Msg)
  46. {
  47. Log(Mod, ptr, _DEFAULT_LOG_LEVEL_, Msg);
  48. }
  49. void basicLogCollection::Log(const char * Mod, void * ptr, const char * Msg)
  50. {
  51. Log(Mod, ptr, _DEFAULT_LOG_LEVEL_, Msg);
  52. }
  53. void basicLogCollection::Log(const char * Mod, void * ptr, _LOG_LEVEL Level, CSTR Msg)
  54. {
  55. #ifdef MEM_DEBUG_LOG
  56. size_t memStat;
  57. char MEM_MSG[256];
  58. memStat = getCurrentRSS();
  59. sprintf(MEM_MSG, "MemStat: %d\n", memStat);
  60. broadcast(MEM_MSG);
  61. #endif
  62. if (Level <= m_bMaxLevel)
  63. {
  64. char temp[MAX_LOG_MSG_SIZE];
  65. if (strlen(Msg) < (MAX_LOG_MSG_SIZE - 120))
  66. {
  67. time_t LocalTime;
  68. time(&LocalTime);
  69. #ifndef __linux__
  70. tm * gmt_time = NULL;
  71. gmt_time = gmtime(&LocalTime);
  72. #else
  73. tm gmtt;
  74. tm * gmt_time = &gmtt;
  75. if (gmtime_r(&LocalTime, &gmtt) == NULL)
  76. {
  77. return;
  78. }
  79. #endif
  80. switch (m_bLogSettings)
  81. {
  82. case _LOG_SIMPLE: sprintf(temp, "%s: %s\n", Mod, Msg); break;
  83. case _LOG_TIME:
  84. {
  85. sprintf(temp, "%04d-%02d-%02d %02d:%02d:%02d %s: %s\n", 1900 + gmt_time->tm_year, 1 + gmt_time->tm_mon, gmt_time->tm_mday, gmt_time->tm_hour, gmt_time->tm_min, gmt_time->tm_sec, Mod, Msg);
  86. break;
  87. };
  88. case _LOG_PTR: sprintf(temp, "%p %s: %s\n", ptr, Mod, Msg); break;
  89. case _LOG_TIME_PTR:
  90. {
  91. sprintf(temp, "%04d-%02d-%02d %02d:%02d:%02d %p %s: %s\n", 1900 + gmt_time->tm_year, 1 + gmt_time->tm_mon, gmt_time->tm_mday, gmt_time->tm_hour, gmt_time->tm_min, gmt_time->tm_sec, ptr, Mod, Msg);
  92. break;
  93. };
  94. case _LOG_LVL: sprintf(temp, "%02X %s: %s\n", Level, Mod, Msg); break;
  95. case _LOG_LVL_TIME:
  96. {
  97. sprintf(temp, "%02X %04d-%02d-%02d %02d:%02d:%02d %s: %s\n", Level, 1900 + gmt_time->tm_year, 1 + gmt_time->tm_mon, gmt_time->tm_mday, gmt_time->tm_hour, gmt_time->tm_min, gmt_time->tm_sec, Mod, Msg);
  98. break;
  99. };
  100. case _LOG_LVL_PTR: sprintf(temp, "%02X %p %s: %s\n", Level, ptr, Mod, Msg); break;
  101. case _LOG_LVL_TIME_PTR:
  102. {
  103. sprintf(temp, "%02X %04d-%02d-%02d %02d:%02d:%02d %p %s: %s\n", Level, 1900 + gmt_time->tm_year, 1 + gmt_time->tm_mon, gmt_time->tm_mday, gmt_time->tm_hour, gmt_time->tm_min, gmt_time->tm_sec, ptr, Mod, Msg);
  104. break;
  105. };
  106. };
  107. broadcast((CSTR) temp);
  108. }
  109. else
  110. {
  111. sprintf(temp, "Log Message Too Long Buffer is Overflowed Splitting!");
  112. broadcast((CSTR) temp);
  113. };
  114. };
  115. }
  116. void basicLogCollection::Log(const char * Mod, void * ptr, _LOG_LEVEL Level, const char * Msg)
  117. {
  118. Log(Mod, ptr, Level, (CSTR) Msg);
  119. }