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.

49 lines
1.7 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
3 years ago
​
​
​
​
​
3 years ago
​
​
3 years ago
​
​
​
​
3 years ago
​
​
​
6 years ago
7 years ago
7 years ago
​
​
​
  1. #include "objectFileLoggingService.h"
  2. objectFileLoggingService::objectFileLoggingService( const char *FileName ){
  3. memset( m_pFileName, 0, MAX_PATH_LEN );
  4. strncpy( m_pFileName, FileName, MAX_PATH_LEN-1 );
  5. m_bLogging = true;
  6. };
  7. objectFileLoggingService::objectFileLoggingService( CSTR FileName ){
  8. memset( m_pFileName, 0, MAX_PATH_LEN );
  9. strncpy( m_pFileName, FileName, MAX_PATH_LEN-1 );
  10. m_bLogging = true;
  11. };
  12. void objectFileLoggingService::logMessage( CSTR Msg ){
  13. logMessage( (const char *)Msg );
  14. };
  15. void objectFileLoggingService::logMessage( const char *Msg ){
  16. if ( m_bLogging ){
  17. if( getFileSize( m_pFileName ) > MAX_LOG_FILE_SIZE ){
  18. if ( MAX_LOG_FILE_BACKUPS ) {
  19. char tB[MAX_PATH_LEN];
  20. sprintf( tB, "%s.%d", m_pFileName, MAX_LOG_FILE_BACKUPS );
  21. if( fileExist( tB ) ) unlink( tB );
  22. uint8_t ix = MAX_LOG_FILE_BACKUPS;
  23. while( ix ){
  24. char tZ[MAX_PATH_LEN];
  25. sprintf( tZ,"%s.%d", m_pFileName, ix );
  26. if ( ix - 1 ) {
  27. sprintf( tB,"%s.%d", m_pFileName, ix - 1 );
  28. } else {
  29. sprintf( tB,"%s", m_pFileName );
  30. };
  31. if( fileExist( tB ) ) rename( tB, tZ );
  32. ix--;
  33. };
  34. } else {
  35. unlink( m_pFileName );
  36. };
  37. };
  38. FILE *FD;
  39. FD = fopen( m_pFileName , "a+");
  40. if( FD != NULL ) {
  41. fwrite( Msg, 1, strlen(Msg), FD );
  42. fclose(FD);
  43. };
  44. };
  45. };