Пример #1
0
int test_outputfunc()
{
	LOG		*g = NULL ;
	
	g = CreateLogHandle() ;
	if( g == NULL )
	{
		printf( "创建日志句柄失败errno[%d]\n" , errno );
		return -1;
	}
	else
	{
		printf( "创建日志句柄成功\n" );
	}
	
	SetLogOutput( g , LOG_OUTPUT_CALLBACK , "127.0.0.1:514" , & MyOpenLogFirst , NULL , & MyWriteLog , NULL , NULL , & MyCloseLogFinally );
	SetLogLevel( g , LOG_LEVEL_INFO );
	SetLogStyles( g , LOG_STYLES_LOG , LOG_NO_STYLEFUNC );
	
	DebugLog( g , __FILE__ , __LINE__ , "hello iLOG3\n" );
	InfoLog( g , __FILE__ , __LINE__ , "hello iLOG3\n" );
	WarnLog( g , __FILE__ , __LINE__ , "hello iLOG3\n" );
	ErrorLog( g , __FILE__ , __LINE__ , "hello iLOG3\n" );
	FatalLog( g , __FILE__ , __LINE__ , "hello iLOG3\n" );
	
	DestroyLogHandle( g );
	printf( "销毁日志句柄\n" );
	
	return 0;
}
Пример #2
0
bool CLog::Create(const char *pLogFileName, int RolSize/* = OneGBytes*/, bool bOutputConsole/* = true*/)
{
	_outputConsole = bOutputConsole;

	SetLogOutput(std::bind(&CLog::AsyncOutput, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));

	_logThread = new CLogToFileThread(pLogFileName, RolSize);

	_logThread->Start();

	return true;
}
Пример #3
0
int test_press( long count )
{
	LOG		*press = NULL ;
	
	LongToLong	llBegin , llEnd , llDiff ;
	double		dPerf ;
	long		l ;
	
	press = CreateLogHandle() ;
	if( press == NULL )
	{
		printf( "创建press日志句柄失败errno[%d]\n" , errno );
		return -1;
	}
	else
	{
		printf( "创建press日志句柄成功\n" );
	}
	
	/* SetLogOptions( press , LOG_OPTION_OPEN_ONCE ); */
	SetLogOutput( press , LOG_OUTPUT_FILE , "test_press.log" , LOG_NO_OUTPUTFUNC );
	SetLogLevel( press , LOG_LEVEL_INFO );
	SetLogStyles( press , LOG_STYLES_PRESS , LOG_NO_STYLEFUNC );
	SetLogRotateMode( press , LOG_ROTATEMODE_SIZE );
	SetLogRotateSize( press , 10*1024*1024 );
	
	llBegin = GetUnixSecondsExactly() ;
	for( l = 1 ; l <= count ; l++ )
	{
		InfoLog( press , __FILE__ , __LINE__ , "log" );
	}
	llEnd = GetUnixSecondsExactly() ;
	llDiff.high = llEnd.high - llBegin.high ;
	llDiff.low = llEnd.low - llBegin.low ;
	if( llDiff.low < 0 )
	{
		llDiff.low += 1000000 ;
		llDiff.high--;
	}
	dPerf = (double)(count) / ( (double)(llDiff.high) + (double)(llDiff.low) / 1000000 ) ;
	printf( "总耗时[%ld.%03ld] 平均每秒输出行日志[%.2lf]条\n" , llDiff.high , llDiff.low , dPerf );
	
	DestroyLogHandle( press );
	printf( "销毁press句柄环境\n" );
	
	return 0;
}
Пример #4
0
int test_logs()
{
	LOGS		*gs = NULL ;
	LOG		*g = NULL ;
	
	long		index ;
	char		*g_id = NULL ;
	
	char		buffer[ 64 + 1 ] = "" ;
	long		buflen = sizeof(buffer) - 1 ;
	
	int		nret ;
	
	gs = CreateLogsHandle() ;
	if( gs == NULL )
	{
		printf( "创建日志句柄集合失败errno[%d]\n" , errno );
		return -1;
	}
	
	g = CreateLogHandle() ;
	if( g == NULL )
	{
		printf( "创建日志句柄失败errno[%d]\n" , errno );
		return -1;
	}
	
	SetLogOutput( g , LOG_OUTPUT_FILE , "test_logs.log" , LOG_NO_OUTPUTFUNC );
	SetLogLevel( g , LOG_LEVEL_INFO );
	SetLogStyles( g , LOG_STYLES_HELLO , LOG_NO_STYLEFUNC );
	
	AddLogToLogs( gs , "FILE" , g );
	
	AddLogToLogs( gs , "STDERR" , CreateLogHandle() );
	
	g = GetLogFromLogs( gs , "STDERR" ) ;
	if( g == NULL )
	{
		printf( "得到日志句柄失败errno[%d]\n" , errno );
		return -1;
	}
	
	SetLogOutput( g , LOG_OUTPUT_STDERR , "" , LOG_NO_OUTPUTFUNC );
	SetLogLevel( g , LOG_LEVEL_ERROR );
	SetLogStyles( g , LOG_STYLES_HELLO , LOG_NO_STYLEFUNC );
	
	printf( "创建日志句柄集合成功\n" );
	
	for( index = LOG_TRAVELLOG_INDEX_INIT ; ; index++ )
	{
		nret = TravelLogFromLogs( gs , & index , & g_id , & g ) ;
		if( nret )
			break;
		
		printf( "LOG id[%s]\n" , g_id );
	}
	
	printf( "遍历日志句柄集合完成\n" );
	
	DebugLogs( gs , __FILE__ , __LINE__ , "hello iLOG3" );
	InfoLogs( gs , __FILE__ , __LINE__ , "hello iLOG3" );
	WarnLogs( gs , __FILE__ , __LINE__ , "hello iLOG3" );
	ErrorLogs( gs , __FILE__ , __LINE__ , "hello iLOG3" );
	FatalLogs( gs , __FILE__ , __LINE__ , "hello iLOG3" );
	
	DebugHexLogs( gs , __FILE__ , __LINE__ , buffer , buflen , "缓冲区[%ld]" , buflen );
	InfoHexLogs( gs , __FILE__ , __LINE__ , buffer , buflen , "缓冲区[%ld]" , buflen );
	WarnHexLogs( gs , __FILE__ , __LINE__ , buffer , buflen , "缓冲区[%ld]" , buflen );
	ErrorHexLogs( gs , __FILE__ , __LINE__ , buffer , buflen , "缓冲区[%ld]" , buflen );
	FatalHexLogs( gs , __FILE__ , __LINE__ , buffer , buflen , "缓冲区[%ld]" , buflen );
	
	DestroyLogHandle( RemoveOutLogFromLogs( gs , "FILE" ) );
	printf( "销毁日志句柄\n" );
	
	DestroyLogsHandle( gs );
	printf( "销毁日志句柄集合\n" );
	
	return 0;
}