Exemplo n.º 1
0
std::ostringstream& LogContainer<LogOutput>::Get(const LogLevel& level)
{
    mCurrentLogLevel = level;

    if(LogOutput::mShowLogPrefix)
    {
        mOutputStream << gLog.GetLogPrefix() <<" ";
    }

    if(LogOutput::mShowLogTime)
    {
        mOutputStream << GetLogTime(true);
    }

    if(LogOutput::mUseLogTabs)
    {
        //Output tabs
        mOutputStream << string(level > lInfo ? level - lInfo : 0, '\t');
        mOutputStream << "\t";
    }

    if(LogOutput::mShowLogLevel)
    {
         mOutputStream << GetLogLevelAsString(level) << ": "; //Next comes the log message
    }
    return mOutputStream;
}
Exemplo n.º 2
0
void LogFile::append(std::stringstream& ss)
{
	logMutex.lock();

	std::ofstream outfile;
	outfile.open(logName, std::ios_base::app);

	if(outfile.good())
		outfile << GetLogTime() << ": " << ss.str() << "\n";

	logMutex.unlock();
}
Exemplo n.º 3
0
void LogFile::init(std::string name)
{
	logName = name;

#ifdef BT_LOGFILE
	logMutex.lock();

	std::ofstream outfile;
	outfile.open(logName);

	if (outfile.good())
		outfile << GetLogTime() << ": start\n";

	logMutex.unlock();
#endif
}
Exemplo n.º 4
0
/*************************************************************
*				函数名: Report(……)
*				功能:	输出报告
*				参数:	str-输出信息
*						fileId-文件ID
*************************************************************/
void TranscendLog::Report( char *str, unsigned int fileId )
{
	//寻找文件
	ptr_fileList = ptr_fileList_head;
	while( ptr_fileList->uId != fileId && ptr_fileList->next != NULL )
	{
		ptr_fileList = ptr_fileList->next;
	}
	if( ptr_fileList->uId != fileId )
	{
		MessageBox( 0, "OpenFile,Error!", 0, 0 );
		return ;
	}
	FILE *file;
	char *fileName = ptr_fileList->filename;
	file = ptr_fileList->file;
#ifdef DEBUG
	{
		if( file )
		{
			fclose( file );
		}
		if( (file = fopen( fileName, "a"))==NULL )
		{
			MessageBox( 0, "打开文件失败!", 0, 0 );
		}
	}
#endif
	//输出到文件

	if( bSigned && !bTimeSigned)
	{
		fprintf( file, "%s", str );
		fprintf( file, "  FILE:%s,LINE:%d\n",m_fileName, m_iLine);
		if( bConsel )
		{
			printf( "%s", str );
			printf( " FILE:%s,LINE:%d\n",m_fileName, m_iLine );
		}
	}
	else if( bTimeSigned && !bSigned )
	{
		GetLogTime();
		fprintf( file, "%s", str );
		fprintf( file, "  TIME:%s\n", strTime );
		if( bConsel )
		{
			printf( "%s", str );
			printf(  " TIME:%s\n", strTime  );
		}
	}
	else if( bSigned && bTimeSigned )
	{
		fprintf( file, "%s", str );
		fprintf( file, "  FILE:%s,LINE:%d",m_fileName, m_iLine);
		fprintf( file, "  TIME:%s\n", strTime );
		if( bConsel )
		{
			printf( "%s", str );
			printf( " FILE:%s,LINE:%d\n",m_fileName, m_iLine );
		}
	}
	else
	{
		fprintf( file, "%s\n", str );
		//consel窗口
		if( bConsel )
		{
			printf( "%s\n", str );
		}
	}
}