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.

106 lines
4.1 KiB

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