コード例 #1
0
void VHTTPServerLog::_GetLogFilePath (XBOX::VFilePath& outFilepath)
{
	XBOX::VFilePath logFolderPath (fSettings.GetLogPath());

	if (logFolderPath.IsValid() && logFolderPath.IsFolder())
	{
		XBOX::VFolder folder (fSettings.GetLogPath());

		if (!folder.Exists())
			folder.CreateRecursive();
	}

	outFilepath.FromFilePath (fSettings.GetLogPath());
	outFilepath.SetFileName (fSettings.GetLogFileName());
}
コード例 #2
0
XBOX::VError VHTTPServerLog::_Flush()
{
	XBOX::VFilePath	logFilePath;
	XBOX::VError	error = XBOX::VE_OK;

	_GetLogFilePath (logFilePath);

	if (!logFilePath.IsValid())
		return XBOX::VE_FILE_NOT_FOUND;

	if (fLogFileAccessLock.Lock())
	{
		if (NULL == fLogFile)
			fLogFile = new XBOX::VFile (logFilePath);

		if (testAssert (NULL != fLogFile))
		{
			XBOX::VFileDesc *fileDesc = NULL;

			error = fLogFile->Open (XBOX::FA_READ_WRITE, &fileDesc, XBOX::FO_CreateIfNotFound);

			if ((XBOX::VE_OK == error) && (NULL != fileDesc))
			{
				sLONG8 logFileSize = fileDesc->GetSize();

				if ((CHAR_NUMBER_SIGN != fRequestsBuffer.GetUniChar (1)) && (0 == logFileSize))
				{
					XBOX::VString fileHeader;
					_WriteFileHeader (fileHeader);

					XBOX::StStringConverter<char> buffer (fileHeader, XBOX::VTC_DefaultTextExport);
					fileDesc->SetPos (fileDesc->GetSize());
					error = fileDesc->PutDataAtPos (buffer.GetCPointer(), buffer.GetSize());
					fileDesc->Flush();
				}

				if (fLogBufferAccessLock.Lock())
				{
					// Flushing the buffer
					XBOX::StStringConverter<char> buffer (fRequestsBuffer, XBOX::VTC_DefaultTextExport);
					fileDesc->SetPos (fileDesc->GetSize());
					error = fileDesc->PutDataAtPos (buffer.GetCPointer(), buffer.GetSize());

					fRequestsBuffer.Clear();
					fRequestsInBuffer = 0;

					fLogBufferAccessLock.Unlock();
				}

				error = fileDesc->Flush();
				fLogFileSize = fileDesc->GetSize();
				delete fileDesc;
				fileDesc = NULL;
			}
			else
			{
				error = VE_CANNOT_OPEN_LOG_FILE;
			}
		}
		else
		{
			error = VE_CANNOT_CREATE_LOG_FILE;
		}

		fLogFileAccessLock.Unlock();

		_CalculateNextFileRotationTime();
	}

	return error;
}