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.8 KiB
107 lines
3.8 KiB
#include "basicLogCollection.h"
|
|
|
|
#ifdef MEM_DEBUG_LOG
|
|
#include "../../alg/generic/heapDebug.h"
|
|
#endif
|
|
|
|
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 ){
|
|
|
|
#ifdef MEM_DEBUG_LOG
|
|
size_t memStat;
|
|
char MEM_MSG[256];
|
|
memStat = getCurrentRSS();
|
|
sprintf( MEM_MSG, "MemStat: %d\n", memStat );
|
|
broadcast( MEM_MSG );
|
|
#endif
|
|
|
|
if( Level <= m_bMaxLevel ){
|
|
char temp[MAX_LOG_MSG_SIZE];
|
|
if( strlen( Msg ) < ( MAX_LOG_MSG_SIZE - 120 ) ) {
|
|
time_t LocalTime;
|
|
time( &LocalTime );
|
|
#ifndef __linux__
|
|
tm* gmt_time = NULL;
|
|
gmt_time = gmtime( &LocalTime );
|
|
#else
|
|
tm gmtt;
|
|
tm* gmt_time = &gmtt;
|
|
if( gmtime_r( &LocalTime, &gmtt ) == NULL ) return;
|
|
#endif
|
|
switch( m_bLogSettings ) {
|
|
case _LOG_SIMPLE: sprintf( temp, "%s: %s\n", Mod, Msg ); break;
|
|
case _LOG_TIME:{
|
|
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: {
|
|
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_LVL_TIME:{
|
|
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 );
|
|
break;
|
|
};
|
|
case _LOG_LVL_PTR: sprintf( temp, "%02X %p %s: %s\n", Level, ptr, Mod, Msg ); break;
|
|
case _LOG_LVL_TIME_PTR:{
|
|
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 );
|
|
break;
|
|
};
|
|
};
|
|
broadcast( (CSTR) temp );
|
|
} else {
|
|
sprintf( temp, "Log Message Too Long Buffer is Overflowed Splitting!" );
|
|
broadcast( (CSTR) temp );
|
|
};
|
|
|
|
};
|
|
};
|
|
|
|
void basicLogCollection::Log( const char *Mod, void *ptr, _LOG_LEVEL Level, const char *Msg ){
|
|
Log( Mod, ptr, Level,(CSTR) Msg );
|
|
};
|