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.
130 lines
3.6 KiB
130 lines
3.6 KiB
#include "basicLogCollection.h"
|
|
|
|
#ifdef MEM_DEBUG_LOG
|
|
#include "../../alg/generic/heapDebug.h"
|
|
#endif
|
|
|
|
basicLogCollection * basicLogCollection::_instance = NULL;
|
|
CSTR basicLogCollection::m_pBroadcastBuffer = NULL;
|
|
|
|
/**
|
|
* Returns the single instance of the object.
|
|
*/
|
|
basicLogCollection * basicLogCollection::getInstance(_LOG_SETTINGS val)
|
|
{
|
|
// check if the instance has been created yet
|
|
if (NULL == _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_mLogMutex.lock();
|
|
m_pRing->add(handler);
|
|
m_mLogMutex.unlock();
|
|
}
|
|
}
|
|
|
|
void basicLogCollection::broadcast(CSTR Msg)
|
|
{
|
|
basicLoggingService * mService = NULL;
|
|
LoggersIterator * mpIterator = NULL;
|
|
m_mLogMutex.lock();
|
|
mpIterator = m_pRing->begin();
|
|
while (mpIterator != NULL)
|
|
{
|
|
mService = m_pRing->getAtCursor(mpIterator);
|
|
mService->logMessage(Msg);
|
|
mpIterator = mpIterator->next;
|
|
};
|
|
m_mLogMutex.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 = getCurrentRSS();
|
|
sprintf(m_pBroadcastBuffer, "MemStat: %d\n", memStat);
|
|
broadcast(m_pBroadcastBuffer);
|
|
#endif
|
|
|
|
if (Level <= m_bMaxLevel)
|
|
{
|
|
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(m_pBroadcastBuffer, "%s: %s\n", Mod, Msg); break;
|
|
case _LOG_TIME:
|
|
{
|
|
sprintf(m_pBroadcastBuffer, "%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(m_pBroadcastBuffer, "%p %s: %s\n", ptr, Mod, Msg); break;
|
|
case _LOG_TIME_PTR:
|
|
{
|
|
sprintf(m_pBroadcastBuffer, "%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(m_pBroadcastBuffer, "%02X %s: %s\n", Level, Mod, Msg); break;
|
|
case _LOG_LVL_TIME:
|
|
{
|
|
sprintf(m_pBroadcastBuffer, "%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(m_pBroadcastBuffer, "%02X %p %s: %s\n", Level, ptr, Mod, Msg); break;
|
|
case _LOG_LVL_TIME_PTR:
|
|
{
|
|
sprintf(m_pBroadcastBuffer, "%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;
|
|
};
|
|
};
|
|
}
|
|
else
|
|
{
|
|
sprintf(m_pBroadcastBuffer, "Log Message Too Long Buffer is Overflowed Splitting!\n");
|
|
};
|
|
broadcast((CSTR) m_pBroadcastBuffer);
|
|
};
|
|
}
|
|
|
|
void basicLogCollection::Log(const char * Mod, void * ptr, _LOG_LEVEL Level, const char * Msg)
|
|
{
|
|
Log(Mod, ptr, Level, (CSTR) Msg);
|
|
}
|