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.

63 lines
1.6 KiB

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() {
  7. // check if the instance has been created yet
  8. if( 0 == _instance ){
  9. // if not, then create it
  10. _instance = new basicLogCollection;
  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. sprintf( temp, " %p %s: %s", ptr, Mod, Msg );
  43. broadcast( (CSTR) temp );
  44. };
  45. };
  46. void basicLogCollection::Log( const char *Mod, void *ptr, _LOG_LEVEL Level, const char *Msg ){
  47. if( Level <= m_bMaxLevel ){
  48. char temp[CLOG];
  49. sprintf( temp, " %p %s: %s", ptr, Mod, Msg );
  50. broadcast( (CSTR) temp );
  51. };
  52. };