From 9a70a96e212dd9c4fe254d17a40c22175fb24764 Mon Sep 17 00:00:00 2001 From: Evgeny Gagua Date: Tue, 12 Dec 2023 03:00:13 -0800 Subject: [PATCH] Mer Super Final --- Projects/la_mojo/build | 4 ++-- lib/components/base/basicFunctionality.cpp | 7 +++++++ lib/components/base/basicFunctionality.h | 5 +++++ .../object/objectFileLoggingService.cpp | 21 +++++++++++++++++++ .../object/objectFileLoggingService.h | 3 +++ 5 files changed, 38 insertions(+), 2 deletions(-) diff --git a/Projects/la_mojo/build b/Projects/la_mojo/build index 70621108..e30c9046 100755 --- a/Projects/la_mojo/build +++ b/Projects/la_mojo/build @@ -2,10 +2,10 @@ #make clean -e "CFG=Debug" -make -e "CFG=Debug" -j6 +#make -e "CFG=Debug" -j6 #make clean -e "CFG=Debug86" -#make -e "CFG=Debug86" -j4 +make -e "CFG=Debug86" -j4 #make clean -e "CFG=Release86" #make -e "CFG=Release86" -j4 diff --git a/lib/components/base/basicFunctionality.cpp b/lib/components/base/basicFunctionality.cpp index 4d142f36..2cf781dc 100644 --- a/lib/components/base/basicFunctionality.cpp +++ b/lib/components/base/basicFunctionality.cpp @@ -163,6 +163,13 @@ bool correctSysTime( int diff ){ return true; }; + +off_t getFileSize(const char *filename) { + struct stat st; + if( stat(filename, &st) == 0 ) return st.st_size; + return -1; +}; + bool correctSoftTime( int diff ){ g_iTimeDiff = diff; return true; diff --git a/lib/components/base/basicFunctionality.h b/lib/components/base/basicFunctionality.h index a873f3c7..87b5ffae 100644 --- a/lib/components/base/basicFunctionality.h +++ b/lib/components/base/basicFunctionality.h @@ -38,6 +38,9 @@ #include #include #endif + #include + #include + #include "basicTypes.h" int fileCopy( const char* source, const char* destination ); @@ -54,6 +57,8 @@ CSTR implode( CArray *Data, CSTR S_Str, U8 Start, U8 End ); CSTR getTStr( CSTR Fmt = NULL ); CSTR getUniqID_SHA256(void); +off_t getFileSize(const char *filename) ; + int rand( int a, int b ); CSTR getUniqID_MD5(void); diff --git a/lib/components/object/objectFileLoggingService.cpp b/lib/components/object/objectFileLoggingService.cpp index d40631e4..db0dafd3 100644 --- a/lib/components/object/objectFileLoggingService.cpp +++ b/lib/components/object/objectFileLoggingService.cpp @@ -18,6 +18,27 @@ void objectFileLoggingService::logMessage( CSTR 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 ) { diff --git a/lib/components/object/objectFileLoggingService.h b/lib/components/object/objectFileLoggingService.h index ce389de3..d8e477fa 100644 --- a/lib/components/object/objectFileLoggingService.h +++ b/lib/components/object/objectFileLoggingService.h @@ -10,6 +10,9 @@ * * @author Gagua */ + +#define MAX_LOG_FILE_SIZE 4194304 //4Mega +#define MAX_LOG_FILE_BACKUPS 4 class objectFileLoggingService : public basicLoggingService { private: bool m_bLogging;