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.

127 lines
3.0 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_pLogMutex;
  38. LoggersRing * m_pRing;
  39. _LOG_LEVEL m_bMaxLevel;
  40. _LOG_SETTINGS m_bLogSettings;
  41. void broadcast(CSTR Msg);
  42. public:
  43. // Method to fetch singleton instance.
  44. static basicLogCollection * getInstance(_LOG_SETTINGS val = _DEFAULT_LOG_SETTINGS);
  45. // Destructor
  46. virtual ~basicLogCollection();
  47. void addHandler(basicLoggingService * handler);
  48. void setLogLevel(_LOG_LEVEL level);
  49. void Log(const char * Mod, void * ptr, CSTR Msg);
  50. void Log(const char * Mod, void * ptr, const char * Msg);
  51. void Log(const char * Mod, void * ptr, _LOG_LEVEL Level, CSTR Msg);
  52. void Log(const char * Mod, void * ptr, _LOG_LEVEL Level, const char * Msg);
  53. protected:
  54. // Constructor - protected so users cannot call it.
  55. explicit basicLogCollection(_LOG_SETTINGS val);
  56. private:
  57. // private static member referencing the single instance of the object
  58. // TODO: Replace basicLogCollection with the type of object you want to
  59. // return the single instance of
  60. static basicLogCollection * _instance;
  61. // Copy constructor
  62. // Declared but not defined to prevent auto-generated
  63. // copy constructor. Refer to "Effective C++" by Meyers
  64. basicLogCollection(const basicLogCollection & src);
  65. // Assignment operator
  66. // Declared but not defined to prevent auto-generated
  67. // assignment operator. Refer to "Effective C++" by Meyers
  68. basicLogCollection & operator=(const basicLogCollection & src);
  69. };
  70. // Constructor implementation
  71. inline basicLogCollection::basicLogCollection(_LOG_SETTINGS val)
  72. {
  73. m_pRing = NULL;
  74. m_bLogSettings = val;
  75. m_pRing = new LoggersRing(); // 4); // Maximum 4 Logginig Engines;
  76. m_bMaxLevel = _DEFAULT_LOG_LEVEL_;
  77. m_pLogMutex = new basicMutex();
  78. }
  79. // Destructor implementation
  80. inline basicLogCollection::~basicLogCollection()
  81. {
  82. if (m_pRing != NULL)
  83. {
  84. delete m_pRing;
  85. }
  86. delete(m_pLogMutex);
  87. }
  88. // TODO: Uncomment the copy constructor when you need it.
  89. // inline basicLogCollection::basicLogCollection(const basicLogCollection& src)
  90. //{
  91. // // TODO: copy
  92. //}
  93. // TODO: Uncomment the assignment operator when you need it.
  94. // inline basicLogCollection& basicLogCollection::operator=(const basicLogCollection& rhs)
  95. //{
  96. // if (this == &rhs) {
  97. // return *this;
  98. // }
  99. //
  100. // // TODO: assignment
  101. //
  102. // return *this;
  103. //}
  104. #endif // __BASICLOGCOLLECTION_H_INCL__