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.

129 lines
3.1 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __BASICLOGCOLLECTION_H_INCL__
  2. #define __BASICLOGCOLLECTION_H_INCL__
  3. #include "basicLoggingService.h"
  4. #include "basicMutex.h"
  5. #define USE_LOCAL_TIME_IN_THE_LOG
  6. #include <time.h>
  7. typedef enum EE_LOG_LEVEL
  8. {
  9. _LOG_NONE = 0,
  10. _LOG_CRITICAL = 1,
  11. _LOG_ERROR,
  12. _LOG_DEBUG,
  13. _LOG_VERBOSE,
  14. _LOG_ALL
  15. } _LOG_LEVEL;
  16. typedef enum EE_LOG_SETTINGS
  17. {
  18. _LOG_SIMPLE = 0,
  19. _LOG_TIME = 1,
  20. _LOG_PTR = 2,
  21. _LOG_TIME_PTR = 3,
  22. _LOG_LVL = 4,
  23. _LOG_LVL_TIME = 5,
  24. _LOG_LVL_PTR = 6,
  25. _LOG_LVL_TIME_PTR = 7
  26. } _LOG_SETTINGS;
  27. #define _DEFAULT_LOG_LEVEL_ _LOG_DEBUG
  28. #define _WORKING_LOG_LEVEL_ _LOG_ALL
  29. #define _DEFAULT_LOG_SETTINGS _LOG_TIME_PTR
  30. /**
  31. * @Description Singleton class to handle logging
  32. *
  33. * @author Gagua
  34. */
  35. class basicLogCollection
  36. {
  37. private:
  38. basicMutex * m_pLogMutex;
  39. LoggersRing * m_pRing;
  40. _LOG_LEVEL m_bMaxLevel;
  41. _LOG_SETTINGS m_bLogSettings;
  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. {
  74. m_pRing = NULL;
  75. m_bLogSettings = val;
  76. m_pRing = new LoggersRing(); // 4); // Maximum 4 Logginig Engines;
  77. m_bMaxLevel = _DEFAULT_LOG_LEVEL_;
  78. m_pLogMutex = new basicMutex();
  79. }
  80. // Destructor implementation
  81. inline basicLogCollection::~basicLogCollection()
  82. {
  83. if (m_pRing != NULL)
  84. {
  85. delete m_pRing;
  86. }
  87. delete(m_pLogMutex);
  88. }
  89. // TODO: Uncomment the copy constructor when you need it.
  90. // inline basicLogCollection::basicLogCollection(const basicLogCollection& src)
  91. //{
  92. // // TODO: copy
  93. //}
  94. // TODO: Uncomment the assignment operator when you need it.
  95. // inline basicLogCollection& basicLogCollection::operator=(const basicLogCollection& rhs)
  96. //{
  97. // if (this == &rhs) {
  98. // return *this;
  99. // }
  100. //
  101. // // TODO: assignment
  102. //
  103. // return *this;
  104. //}
  105. #endif // __BASICLOGCOLLECTION_H_INCL__