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.

98 lines
3.9 KiB

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