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.

146 lines
3.3 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __BASICLOGCOLLECTION_H_INCL__
  2. #define __BASICLOGCOLLECTION_H_INCL__
  3. #include "basicLoggingService.h"
  4. #include "basicMutex.h"
  5. #include <time.h>
  6. typedef enum EE_LOG_LEVEL
  7. {
  8. _LOG_NONE = 0,
  9. _LOG_CRITICAL = 1,
  10. _LOG_ERROR,
  11. _LOG_DEBUG,
  12. _LOG_VERBOSE,
  13. _LOG_ALL
  14. } _LOG_LEVEL;
  15. typedef enum EE_LOG_SETTINGS
  16. {
  17. _LOG_SIMPLE = 0,
  18. _LOG_TIME = 1,
  19. _LOG_PTR = 2,
  20. _LOG_TIME_PTR = 3,
  21. _LOG_LVL = 4,
  22. _LOG_LVL_TIME = 5,
  23. _LOG_LVL_PTR = 6,
  24. _LOG_LVL_TIME_PTR = 7
  25. } _LOG_SETTINGS;
  26. #define _DEFAULT_LOG_LEVEL_ _LOG_DEBUG
  27. #define _WORKING_LOG_LEVEL_ _LOG_ALL
  28. #define _DEFAULT_LOG_SETTINGS _LOG_TIME_PTR
  29. /**
  30. * @Description Singleton class to handle logging
  31. *
  32. * @author Gagua
  33. */
  34. class basicLogCollection
  35. {
  36. private:
  37. basicMutex m_mLogMutex;
  38. LoggersRing * m_pRing;
  39. _LOG_LEVEL m_bMaxLevel;
  40. _LOG_SETTINGS m_bLogSettings;
  41. static CSTR m_pBroadcastBuffer;
  42. void broadcast(CSTR Msg);
  43. public:
  44. // Method to fetch singleton instance.
  45. static basicLogCollection * getInstance(_LOG_SETTINGS val = _DEFAULT_LOG_SETTINGS);
  46. // Destructor
  47. virtual ~basicLogCollection();
  48. void addHandler(basicLoggingService * handler);
  49. void setLogLevel(_LOG_LEVEL level);
  50. void Log(const char * Mod, void * ptr, CSTR Msg);
  51. void Log(const char * Mod, void * ptr, const char * Msg);
  52. void Log(const char * Mod, void * ptr, _LOG_LEVEL Level, CSTR Msg);
  53. void Log(const char * Mod, void * ptr, _LOG_LEVEL Level, const char * Msg);
  54. protected:
  55. // Constructor - protected so users cannot call it.
  56. explicit basicLogCollection(_LOG_SETTINGS val);
  57. private:
  58. // private static member referencing the single instance of the object
  59. // TODO: Replace basicLogCollection with the type of object you want to
  60. // return the single instance of
  61. static basicLogCollection * _instance;
  62. // Copy constructor
  63. // Declared but not defined to prevent auto-generated
  64. // copy constructor. Refer to "Effective C++" by Meyers
  65. basicLogCollection(const basicLogCollection & src);
  66. // Assignment operator
  67. // Declared but not defined to prevent auto-generated
  68. // assignment operator. Refer to "Effective C++" by Meyers
  69. basicLogCollection & operator=(const basicLogCollection & src);
  70. };
  71. // Constructor implementation
  72. inline basicLogCollection::basicLogCollection(_LOG_SETTINGS val) :
  73. m_mLogMutex()
  74. {
  75. m_pBroadcastBuffer = (CSTR) malloc(MAX_LOG_MSG_SIZE);
  76. if (m_pBroadcastBuffer != NULL)
  77. {
  78. m_pRing = new LoggersRing(); // 4); // Maximum 4 Logginig Engines;
  79. if (m_pRing != NULL)
  80. {
  81. m_bLogSettings = val;
  82. memset(m_pBroadcastBuffer, 0, MAX_LOG_MSG_SIZE);
  83. m_bMaxLevel = _DEFAULT_LOG_LEVEL_;
  84. }
  85. else
  86. {
  87. printf("Error Creating MemRing for LogCollection!");
  88. };
  89. }
  90. else
  91. {
  92. m_pRing = NULL;
  93. };
  94. }
  95. // Destructor implementation
  96. inline basicLogCollection::~basicLogCollection()
  97. {
  98. if (m_pRing != NULL)
  99. {
  100. delete m_pRing;
  101. }
  102. if (m_pBroadcastBuffer != NULL)
  103. {
  104. free(m_pBroadcastBuffer);
  105. }
  106. }
  107. // TODO: Uncomment the copy constructor when you need it.
  108. // inline basicLogCollection::basicLogCollection(const basicLogCollection& src)
  109. //{
  110. // // TODO: copy
  111. //}
  112. // TODO: Uncomment the assignment operator when you need it.
  113. // inline basicLogCollection& basicLogCollection::operator=(const basicLogCollection& rhs)
  114. //{
  115. // if (this == &rhs) {
  116. // return *this;
  117. // }
  118. //
  119. // // TODO: assignment
  120. //
  121. // return *this;
  122. //}
  123. #endif // __BASICLOGCOLLECTION_H_INCL__