C/C++ code#include "nfx.h"
//#ifdef LINUX_PLATFORM
#include
#include
#include
#include
#include
#include
//#endif
#include
#include
#include
#include
#include
#include "Log.h"
using namespace std;
/******************************************************/
/**/const U32 DefLogLevel = CLOG_LEVEL_ALL;
/******************************************************/
const char* LogFileDir = "./Log";
void CLog::init( void )
{
}
CLog::CLog( void ):m_tid(pthread_self( ))
{
this->init( );
}
void CLog::getThreadName( char* threadName )
{
DIR* dp;
struct dirent* entry;
struct stat statbuf;
if( ( dp = opendir( LogFileDir ) ) == NULL )
{
fprintf( stderr,"cannot open directory \n");
return;
}
//chdir( dir );
while( ( entry = readdir( dp ) )!=NULL )
{
lstat( entry->d_name,&statbuf );
if( !S_ISDIR( statbuf.st_mode ) )
{
fstream logfile;
logfile.open( entry->d_name,ifstream::in );
logfile.seekg(0,fstream::beg);
string titlebuf;
cout<d_name<
while(logfile>>titlebuf)
{
cout<
}
fstream::iostate oldstate = logfile.rdstate( );
logfile.close();
}
}
}
CLog::CLog( char * threadName ):m_tid(pthread_self( ))
{
this->init( );
getThreadName( threadName );
}
CLog::~CLog()
{
}
void CLog::formatPrint(const char *title,va_list args )
{
FILE * filestream = fopen("./Log/DebugLog","a");
fprintf(filestream,"\n<===FILE : %s LINE : %d DATA : %s TIME : %s===>\n",__FILE__,__LINE__,__DATE__,__TIME__);
vfprintf(filestream,title,args);
fprintf(filestream,"\n");
fclose(filestream);
}
void CLog::Log(U32 level,const char * title,...)
{
if(DefLogLevel & level)
{
va_list arg_ptr;
va_start( arg_ptr,title );
this->formatPrint(title, arg_ptr );
va_end( arg_ptr );
}
}
void CLog::Logif( U32 level,bool condition,const char * title,... )
{
if(condition && (DefLogLevel & level))
{
va_list arg_ptr;
va_start( arg_ptr,title );
this->formatPrint( title,arg_ptr );
va_end( arg_ptr );
}
}