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.
 
 
 
 
 
 

51 lines
1.8 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[MAX_PATH_LEN];
sprintf( tB, "%s.%d", m_pFileName, MAX_LOG_FILE_BACKUPS );
if( fileExist( tB ) ) unlink( tB );
uint8_t ix = 0;
do{
char tZ[MAX_PATH_LEN];
if ( ix ) {
sprintf( tB,"%s.%d", m_pFileName, ix++ );
sprintf( tZ,"%s.%d", m_pFileName, ix++ );
} else {
sprintf( tB,"%s", m_pFileName );
sprintf( tZ,"%s.%d", m_pFileName, ++ix );
};
rename( tB, tZ );
}while( ix < MAX_LOG_FILE_BACKUPS );
} else {
unlink( m_pFileName );
};
};
FILE *FD;
FD = fopen( m_pFileName , "a+");
if( FD != NULL ) {
fwrite( Msg, 1, strlen(Msg), FD );
fclose(FD);
} else {
printf( "Totally Lost\n" );
};
};
};