Exemple #1
0
	DC_ID CLogModule::Create_Log_File( const std::string& Name, const std::string& Filename) {
		CLogFile* pLogFile = new CLogFile();
		
		pLogFile->SetLogFile(Filename);
		pLogFile->SetName(Name);


		// Add to list of registered log files
		m_Logfiles.insert( LOGFILE_MAP_PAIR(pLogFile->GetID(),pLogFile) );
		
		return pLogFile->GetID();
	}
Exemple #2
0
	// Debug Log()
	void CLogModule::Debug_Log(DC_ID LogID, const char* Format, ...) {
		if( !CDCEngine::GetInstance()->IsDebugMode()) {
			return;
		}
		
		// Find the logfile obj
		LOGFILE_MAP_ITER iFind = m_Logfiles.find( LogID );
		if( iFind == m_Logfiles.end() ) {
			// No logfile...are we still init'ing?
			return;
		}
		
		CLogFile* pLogFile = iFind->second;
		
		string Text;
		char buf[100];
		
		va_list va;
		va_start(va, Format);
		vsprintf(buf,Format, va);
		va_end(va);
		
		Text = buf;
		
		// Get the time
		time_t now;
		struct tm* pTime;
		time(&now);
		pTime = localtime(&now);
		char time_buf[100];
		sprintf( time_buf, "%d/%d/%d-%d:%d:%d", pTime->tm_mon, pTime->tm_mday, pTime->tm_year + 1900, pTime->tm_hour, pTime->tm_min, pTime->tm_sec );
		string Time = time_buf;
		
		string Name = "[";
		Name += pLogFile->m_sName;
		Name += "]";
		
		if( pLogFile->GetID() == LOG_MAIN ) {
			sprintf(buf, "%-9s %s: %s", Name.c_str(), Time.c_str(), Text.c_str());
			Text = buf;
			
			// If the main log file is hooked, call it
			if( m_MainLogFileHook ) {
				(*m_MainLogFileHook)( Text.c_str() );
			}
		}
		
		pLogFile->Write( Text );
		
		// If this is not the main logfile, copy it there
		if( pLogFile->GetID() != LOG_MAIN ) {
			iFind = m_Logfiles.find( LOG_MAIN );
			CLogFile* pMainLog = iFind->second;
			
			sprintf(buf, "%-9s %s: %s", Name.c_str(), Time.c_str(), Text.c_str());
			Text = buf;
			pMainLog->Write( Text );

			// If the main log file is hooked, call it
			if( m_MainLogFileHook ) {
				(*m_MainLogFileHook)( Text.c_str() );
			}
		}
		
	}