/** * Find the name and size of the file which will be used for logging. * ie. file name which contains max file count */ void CBaseLogObject::vGetNameAndSizeOfCurrentLogFile() { //Two conditions to search for the current file present at the main file //path folder //1.If logging is initialised //2.if file name is modified ie.m_omCurrLogFile belongs to diff. main file cycle //Find file only if current file is not same as main file if (m_omCurrLogFile.Compare(m_sLogInfo.m_sLogFileName)) { //Check if the curr file doesn't belong to main file group if (m_omCurrLogFile.GetLength() >= MIN_NAME_LENGTH) { CString omTempFile = m_omCurrLogFile.Left(m_omCurrLogFile.GetLength() - 2); if ( !omTempFile.Compare(m_sLogInfo.m_sLogFileName) ) { //If curr file belongs to main file group then do nothing return; } } if (ENOENT != _taccess(m_sLogInfo.m_sLogFileName, 0)) { CString strNextFile = omAddGroupCountToFileName(1, m_sLogInfo.m_sLogFileName); if (ENOENT != _taccess(strNextFile, 0)) { //If first file is not present then current file is main file m_omCurrLogFile = m_sLogInfo.m_sLogFileName; } else { //Search for the file in a group with highest count m_nCurrFileCnt = 0; for (int i = 2; (i <= MAX_LOG_FILE_IN_GRP) && (m_nCurrFileCnt != 0); i++) { strNextFile = omAddGroupCountToFileName(i, m_sLogInfo.m_sLogFileName); if (ENOENT != _taccess(strNextFile, 0)) { //If this file is not found means the last file is target file m_nCurrFileCnt = --i; } } m_omCurrLogFile = omAddGroupCountToFileName(m_nCurrFileCnt, m_sLogInfo.m_sLogFileName); } //Now find the size of the file m_dTotalBytes = dwGetFileSize(m_omCurrLogFile); } else { //If main file is not present initialise the current file //with main file m_omCurrLogFile = m_sLogInfo.m_sLogFileName; m_dTotalBytes = 0; m_nCurrFileCnt = 0; } } }
/** * \brief Start logging * \req RS_12_23 Start logging * * To do actions before logging starts. */ BOOL CBaseLogObject::bStartLogging(void) { BOOL bResult = FALSE; if ((m_pLogFile == NULL) && (m_sLogInfo.m_bEnabled)) { // This function should be called every time logging is started m_CurrTriggerType = m_sLogInfo.m_sLogTrigger.m_unTriggerType; char Mode[2] = _T(" "); Mode[0] = (m_sLogInfo.m_eFileMode == APPEND_MODE) ? L'a' : L'w'; EnterCriticalSection(&m_CritSection); //In case user has deleted the content of the file m_dTotalBytes = dwGetFileSize(m_omCurrLogFile); //If it is new session always overwrite the file if (m_dTotalBytes >= DEFAULT_FILE_SIZE_IN_BYTES && m_bNewSession) { Mode[0] = L'w'; m_dTotalBytes = 0; } if (m_sLogInfo.m_eFileMode == OVERWRITE_MODE) { m_dTotalBytes = 0; } fopen_s(&m_pLogFile, m_omCurrLogFile, Mode); if (m_pLogFile != NULL) { CString omHeader = ""; vFormatHeader(omHeader); _ftprintf(m_pLogFile, _T("%s"), omHeader.GetBuffer(MAX_PATH)); bResult = TRUE; } LeaveCriticalSection(&m_CritSection); } return bResult; }