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

#include "basicLogCollection.h"
basicLogCollection* basicLogCollection::_instance = 0;
/**
* Returns the single instance of the object.
*/
basicLogCollection* basicLogCollection::getInstance( _LOG_SETTINGS val ) {
// check if the instance has been created yet
if( 0 == _instance ){
// if not, then create it
_instance = new basicLogCollection( val );
};
// return the single instance
return _instance;
};
void basicLogCollection::addHandler( basicLoggingService *handler ){
if( m_pRing != NULL ) m_pRing->add( handler );
};
void basicLogCollection::broadcast( CSTR Msg ){
basicLoggingService *mService;
LoggersIterator *mpIterator;
m_pLogMutex->lock();
mpIterator = m_pRing->begin();
while( mpIterator != NULL ){
mService = m_pRing->getAtCursor( mpIterator );
mService->logMessage( Msg );
mpIterator = mpIterator->next;
};
m_pLogMutex->unlock();
};
void basicLogCollection::setLogLevel( _LOG_LEVEL level ){
m_bMaxLevel = level;
};
void basicLogCollection::Log( const char *Mod, void *ptr, CSTR Msg ){
Log( Mod, ptr, m_bMaxLevel, Msg );
};
void basicLogCollection::Log( const char *Mod, void *ptr, const char *Msg ){
Log( Mod, ptr, m_bMaxLevel, Msg );
};
void basicLogCollection::Log( const char *Mod, void *ptr, _LOG_LEVEL Level, CSTR Msg ){
if( Level <= m_bMaxLevel ){
char temp[CLOG];
if( strlen( Msg ) < ( CLOG >> 1 ) ) {
switch( m_bLogSettings ) {
case _LOG_SIMPLE: sprintf( temp, "%s: %s\n", Mod, Msg ); break;
case _LOG_TIME:{
time_t LocalTime;
tm *gmt_time;
time( &LocalTime );
gmt_time = gmtime( &LocalTime );
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 );
break;
};
case _LOG_PTR: sprintf( temp, "%p %s: %s\n", ptr, Mod, Msg ); break;
case _LOG_TIME_PTR: {
time_t LocalTime;
tm *gmt_time;
time( &LocalTime );
gmt_time = gmtime( &LocalTime );
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 );
break;
};
case _LOG_LVL: sprintf( temp, "%02X %s: %s\n", Level, Mod, Msg ); break;
case _LOG_TIME_LVL:{
time_t LocalTime;
tm *gmt_time;
time( &LocalTime );
gmt_time = gmtime( &LocalTime );
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 );
break;
};
case _LOG_LVL_PTR: sprintf( temp, "%02X %p %s: %s\n", Level, ptr, Mod, Msg ); break;
case _LOG_TIME_LVL_PTR:{
time_t LocalTime;
tm *gmt_time;
time( &LocalTime );
gmt_time = gmtime( &LocalTime );
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 );
break;
};
};
} else {
sprintf( temp, "Log Message Too Long Buffer is Overflowed" );
};
broadcast( (CSTR) temp );
};
};
void basicLogCollection::Log( const char *Mod, void *ptr, _LOG_LEVEL Level, const char *Msg ){
Log( Mod, ptr, Level,(CSTR) Msg );
};