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.

123 lines
3.9 KiB

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