コード例 #1
0
//						===============
void					Log::Initialise
//						===============
(
	EngineSetting*		pSetting	// pointer to Setting object
)
{
	// Set the log name to the name of the cluster; place the '@' character
	// after it.
	m_strLogName = pSetting->Get( "CLUSTER", "FileName" ) + "@";

	// Make a string out of the current date and time (separated by an
	// underscore), and add this to the back of the file name.
	DateTime dt;
	m_strLogName += dt.Get( "YYYYMMDD_hhmmss" );

	// Replace all characters that are not allowed in a file name by underscores.
	string::size_type nChar;
	while ( (nChar = m_strLogName.find_first_of( NOT_ALLOWED_IN_FILE )) != string::npos )
	{
		m_strLogName.replace( nChar, 1, "_" );
	}

	// Create a FileName object of the log name; set its extension;
	// set its location as specified in the settings.
	FileName fnLog( m_strLogName );
	fnLog.ChangeExtension( LOG_EXTENSION );
	fnLog.ChangeLocation( pSetting->Get( "LOG", "Path" ) );

	// Determine if the file name is unique.
	int nCounter = 0;
	bool bUnique = false;
	while ( !bUnique )
	{
		// If the name was already once found to be not unique, add
		// another '#' character to the back of the name.
		if ( nCounter > 0 )
		{
			fnLog.ChangeName( fnLog.GetName() + "#" );
		}

		// Get the new log file.
		m_strLogName = fnLog.GetFile();

		// Determine if a file with this name/location already exists.
		if( FileExists( m_strLogName ) )
		{
			// File name already exists; update counter.
			nCounter++;
		}
		else
		{
			bUnique = true;
		}
	}

	// Open the output medium for writing, and check if this succeeds.
	if ( Open( m_strLogName, WRITE ) )
	{
		m_bGood = true;
	}
}