Пример #1
0
/**
 * 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;
        }
    }
}
Пример #2
0
/**
 * Equal operator
 */
CBaseLogObject& CBaseLogObject::operator=(const CBaseLogObject& RefObj)
{
    RefObj.GetLogInfo(m_sLogInfo);
    m_omCurrLogFile = RefObj.m_omCurrLogFile;
    m_nCurrFileCnt = RefObj.m_nCurrFileCnt;
    m_dTotalBytes = RefObj.m_dTotalBytes;

    // Update the log file name based on the current file count to update the data
    // This occurs when some of the config dialog members are changed
    if (m_nCurrFileCnt > 0)
    {
        int nIdx = m_omCurrLogFile.Find('_');

        if (nIdx != -1)
        {
            m_omCurrLogFile = m_omCurrLogFile.Left(nIdx);
            m_omCurrLogFile += ".log";
        }

        m_omCurrLogFile = omAddGroupCountToFileName(m_nCurrFileCnt, m_omCurrLogFile.GetBuffer(MAX_CHAR));
    }

    Der_CopySpecificData(&RefObj);
    return *this;
}
Пример #3
0
void CBaseLogObject::vSetNextFileName(void)
{
    //If it is not default file then remove "_File count no."
    if (_tcscmp(m_omCurrLogFile.GetBuffer(MAX_PATH), m_sLogInfo.m_sLogFileName) &&
        m_omCurrLogFile.GetLength() > 2)
    {
        m_omCurrLogFile.Left(m_omCurrLogFile.GetLength() - 2);
    }

    if ( ++m_nCurrFileCnt > MAX_LOG_FILE_IN_GRP)
    {
        //If it reaches max start again
        m_nCurrFileCnt = 0;
        m_omCurrLogFile = m_sLogInfo.m_sLogFileName;
    }
    else
    {
        //Add the file count with "_"
        m_omCurrLogFile = omAddGroupCountToFileName(m_nCurrFileCnt, 
                                                m_sLogInfo.m_sLogFileName);
    }
}