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.
69 lines
1.3 KiB
69 lines
1.3 KiB
#include "objectFileLoggingService.h"
|
|
|
|
objectFileLoggingService::objectFileLoggingService(const char * FileName)
|
|
{
|
|
memset(m_pFileName, 0, MAX_PATH_LEN);
|
|
strncpy(m_pFileName, FileName, MAX_PATH_LEN - 1);
|
|
m_bLogging = true;
|
|
}
|
|
|
|
objectFileLoggingService::objectFileLoggingService(CSTR FileName)
|
|
{
|
|
memset(m_pFileName, 0, MAX_PATH_LEN);
|
|
strncpy(m_pFileName, FileName, MAX_PATH_LEN - 1);
|
|
m_bLogging = true;
|
|
}
|
|
|
|
void objectFileLoggingService::logMessage(CSTR Msg)
|
|
{
|
|
logMessage((const char *) Msg);
|
|
}
|
|
|
|
void objectFileLoggingService::logMessage(const char * Msg)
|
|
{
|
|
if (m_bLogging)
|
|
{
|
|
if (getFileSize(m_pFileName) > MAX_LOG_FILE_SIZE)
|
|
{
|
|
if (MAX_LOG_FILE_BACKUPS)
|
|
{
|
|
char tB[2048];
|
|
sprintf(tB, "%s.%d", m_pFileName, MAX_LOG_FILE_BACKUPS);
|
|
if (fileExist(tB))
|
|
{
|
|
unlink(tB);
|
|
}
|
|
uint8_t ix = MAX_LOG_FILE_BACKUPS;
|
|
while (ix)
|
|
{
|
|
char tZ[2048];
|
|
sprintf(tZ, "%s.%d", m_pFileName, ix);
|
|
if (ix - 1)
|
|
{
|
|
sprintf(tB, "%s.%d", m_pFileName, ix - 1);
|
|
}
|
|
else
|
|
{
|
|
sprintf(tB, "%s", m_pFileName);
|
|
};
|
|
if (fileExist(tB))
|
|
{
|
|
rename(tB, tZ);
|
|
}
|
|
ix--;
|
|
};
|
|
}
|
|
else
|
|
{
|
|
unlink(m_pFileName);
|
|
};
|
|
};
|
|
FILE * FD;
|
|
FD = fopen(m_pFileName, "a+");
|
|
if (FD != NULL)
|
|
{
|
|
fwrite(Msg, 1, strlen(Msg), FD);
|
|
fclose(FD);
|
|
};
|
|
};
|
|
}
|