Esempio n. 1
0
	//Open File and Append
	bool EventLogger::flush()
	{
		if(m_lstLog.size() == 0)
			return false;

		ofstream ofs;
		if(FileExists(m_strFP))		
			ofs.open(m_strFP.cptr(), ios::out | ios::app);
		else
			ofs.open(m_strFP.cptr(), ios::out);
		if(!ofs.is_open())
			return false;

		DAnsiStr strLine;
		for(size_t i=0; i < m_lstLog.size(); i++)
		{
			strLine = m_lstLog[i];
			if(strLine.length() > 0)
			{
				ofs << strLine << '\0' << endl;
			}
		}
		ofs.close();

		m_lstLog.resize(0);
		m_szBufferSize = 0;
		return true;
	}
Esempio n. 2
0
	void EventLogger::add(const char* lpStrDesc, EVENTTYPE t, 
		const char* lpStrSource, int value)
	{
		if(lpStrDesc == NULL)
			return;

		DAnsiStr strEvent;			
		//Write Event Type
		if(m_bWriteEventTypes)
		{
			if(t == etInfo)
				strEvent += printToAStr("INFO: ");
			else if(t == etWarning)
				strEvent += printToAStr("WARNING: ");
			else if(t == etError)
				strEvent += printToAStr("ERROR: ");
		}

		//Write Event Time
		if(m_bWriteTimeStamps)
		{
			time_t rawtime;
			time (&rawtime);
#ifdef PS_SECURE_API
			char buffer[64];
			struct tm timeinfo;
			localtime_s(&timeinfo, &rawtime);
			asctime_s(timeinfo, buffer, 64)
				strEvent += printToAStr("TIME: [%s], ", buffer);
#else
			struct tm * timeinfo = localtime ( &rawtime );
			DAnsiStr strTime = DAnsiStr(asctime(timeinfo));
			strTime.trim();
			strEvent += printToAStr("TIME: [%s], ", strTime.cptr());
#endif
		}

		//Write Source + Value
		if(m_bWriteSourceInfo && lpStrSource)
		{
			strEvent += printToAStr("SOURCE: [%s, LINE:%d], ", lpStrSource, value);
		}

		//Write Event itself
		strEvent += DAnsiStr(lpStrDesc);			
		m_lstLog.push_back(strEvent);

		//Write Message to screen
		if(m_bWriteToScreen)
			display(strEvent.cptr());

		//Update Buffer size and Flush if ready
		m_szBufferSize += strEvent.length();
		if(m_szBufferSize > PS_LOG_BUFFER_SIZE)
			flush();
	}
Esempio n. 3
0
	//Write down our csv file
	bool CPerfTest::writeCSV()
	{
		ofstream ofs;
		bool bWriteHeader = true;

		if(m_writeResultsBehavior == wtrIgnore)
			return false;

		if(m_writeResultsBehavior == wtrAppendExisting)
		{
			if(PS::FILESTRINGUTILS::GetFileSize(m_strFileName.ptr()) > 0)
				bWriteHeader = false;
			ofs.open(m_strFileName.ptr(), ios::out | ios::app);
		}
		else
			ofs.open(m_strFileName.ptr(), ios::out | ios::trunc);

		if(!ofs.is_open())
			return false;
		
		//Write header
		if((m_headers.size() > 0)&&(bWriteHeader))
		{
			DAnsiStr strHeader;
			for(size_t i=0; i < m_headers.size(); i++)
			{
				if(i == m_headers.size() - 1)
					strHeader += m_headers[i];
				else
					strHeader += m_headers[i] + ",";
			}			
			ofs << strHeader << '\0' << '\n';
		}

		DAnsiStr strLine;
		//Write test results		
		for(size_t i=0; i < m_content.size(); i++)
		{
			strLine = m_content[i];
			if(strLine.length() > 0)		
				ofs << strLine << '\0' << '\n';			
		}
		ofs.close();

		return true;
	}