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.

107 lines
3.9 KiB

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