Ejemplo n.º 1
0
int CLog::PrintLog(LogType nLogType, const char * pLog, ...)
{
	try
	{
		if(IsNull()!=0)
		{
			fprintf(m_pLog, "Invalid log file path and set as default!");
			fflush(m_pLog);
		}
		va_list args;	// 变参链表 [ZuoW,2010/3/11]

		va_start(args, pLog);	// 将可变参数转换位变参链表
		// 组织日志语句
		FormatLog(nLogType, pLog, args);

		va_end(args);

		// 输出日志到文件
		fflush(m_pLog);

	}
	catch(...)
	{
		return FAIL;
	}

	return SUCCESS;
}
Ejemplo n.º 2
0
void Log::LogMessageVarg(LogMessageType messageType, const char* fmt, va_list argList)
{
    if ((messageType & LoggingMask) == 0)
        return;
#ifndef OVR_BUILD_DEBUG
    if (IsDebugMessage(messageType))
        return;
#endif

    char  buffer[MaxLogBufferMessageSize];
    char* pBuffer = buffer;
    char* pAllocated = NULL;

    #if !defined(OVR_CC_MSVC) // Non-Microsoft compilers require you to save a copy of the va_list.
        va_list argListSaved;
        va_copy(argListSaved, argList);
    #endif

    int result = FormatLog(pBuffer, MaxLogBufferMessageSize, messageType, fmt, argList);

    if(result >= MaxLogBufferMessageSize) // If there was insufficient capacity...
    {
        // We assume C++ exceptions are disabled.
        // FormatLog will handle the case that pAllocated is NULL.
        pAllocated = new char [result + 1];
        // We cannot use OVR_ALLOC() for this allocation because the logging subsystem exists
        // outside of the rest of LibOVR so that it can be used to log events from anywhere.
        pBuffer = pAllocated;

        #if !defined(OVR_CC_MSVC)
            va_end(argList); // The caller owns argList and will call va_end on it.
            va_copy(argList, argListSaved);
        #endif

        FormatLog(pBuffer, (size_t)result + 1, messageType, fmt, argList);
    }

    DefaultLogOutput(pBuffer, messageType, result);
    delete[] pAllocated;
}
Ejemplo n.º 3
0
int CLog::PrintLog(LogType nLogType, std::string strLog,...)
{
	try
	{
		if(IsNull()!=0)
		{
			fprintf(m_pLog, "Invalid log file path and set as default!");
			fflush(m_pLog);
		}

		va_list args;	// 可变参数链表 [ZuoW,2010/3/11]
		va_start(args, strLog);		/// va_start 的第二个参数不是最后一个有名参数 [ZuoW,2010/6/8]

		FormatLog(nLogType, strLog.c_str(), args);

		fflush(m_pLog);
	}
	catch(...)
	{
		return FAIL;
	}

	return SUCCESS;
}