void CLog::WriteFuncEnd(T x) { #ifdef WRITE_LOG_ENABLE char szPath[PATH_MAX] = {0}; GetLogFilePath(szPath); ofstream fout(szPath,ios::app); fout.seekp(ios::end); fout << GetSystemTime() << "--------------------"<< x <<" End --------------------" << endl; fout.close(); #elseif DEBUG std::cout << GetSystemTime() << "--------------------"<< x <<" End --------------------" << std::endl; #endif }
void CLog::WriteLog2(T1 x1,T2 x2) { #ifdef WRITE_LOG_ENABLE char szPath[PATH_MAX] = {0}; GetLogFilePath(szPath); ofstream fout(szPath,ios::app); fout.seekp(ios::end); fout << GetSystemTime() << x1 <<" = "<< x2 << endl; fout.close(); #elseif DEBUG std::cout << GetSystemTime() << x1 << "=" << x2 << std::endl; #endif }
ERMsg CBioSIMProject::Execute(const CFileManager& fileManager, CCallback& callback) { ERMsg msg; //callback.PushTask("Main loop over components", GetNbExecute(false)); msg += ExecuteChild(fileManager, callback); //callback.PopTask(); string logText = GetOutputString(msg, callback, true); string filePath = GetLogFilePath(GetPath(fileManager)); msg += WriteOutputMessage(filePath, logText); return msg; }
const CLog::SOpenFile* CLog::GetLogFile( EErrorMsg_Type eType ) { static SOpenFile* pOpenFile; pOpenFile = NULL; // 日志文件对象获得 if ( eType > eERROR_MSG_TYPE_START && eType < eERROR_MSG_TYPE_NUMBERS ) { MapLogFileItr itr = m_mapLogFile.find( eType ); if ( itr != m_mapLogFile.end() ) { // 获得已打开的日志文件对象 pOpenFile = &(itr->second); } else { // 创建新日志文件对象 pair<MapLogFileItr, bool> ret = m_mapLogFile.insert( make_pair(eType, SOpenFile()) ); if ( ret.second == true ) { pOpenFile = &(ret.first->second); } } } // 日志文件指针维护 CTime tempTime = CTime::GetCurrentTime(); if( pOpenFile != NULL ) { // 日志文件维护 if ( pOpenFile->pFile == NULL || (pOpenFile->cTime.GetDay() != tempTime.GetDay()) ) { if(pOpenFile->pFile != NULL) fclose(pOpenFile->pFile); TString strFliePath; GetLogFilePath( eType, strFliePath ); pOpenFile->pFile = _tfsopen(strFliePath.c_str(), _T("a+t"), _SH_DENYNO); if (pOpenFile->pFile != NULL) { pOpenFile->cTime = tempTime; } } } return pOpenFile; }