|
/**
* Boby Thomas June 2007
*
*/
#include "logger.h"
CLogger* CLogger::logger;
CLogger::CLogger()
{
loggerFileCS = new CRITICAL_SECTION;
InitializeCriticalSection(loggerFileCS);
}
CLogger::~CLogger()
{
if(logger != NULL)
{
delete logger;
logger = NULL;
}
if(loggerFileCS != NULL)
{
DeleteCriticalSection(loggerFileCS);
loggerFileCS = NULL;
}
}
void CLogger::fileLog(string fileName, string message)
{
#ifdef TRACE_FILE
// write to the file
//ofstream seems to be dangerous in multithreded environment.
/* ofstream outFileStream;
outFileStream.open(sFileName.c_str(),ios::app);
if(!(outFileStream.bad() || outFileStream.fail()))
outFileStream.write(message.c_str(),message.length());
outFileStream.close();
*/
FILE * fp = fopen(fileName.c_str(),"a++");
if(fp != NULL)
{
fwrite(message.c_str(),sizeof(char),message.length(),fp);
fclose(fp);
}
#endif //TRACE_FILE
}
void CLogger::log(int logLevel,const char * pcFormat,...)
{
#ifdef TRACE
EnterCriticalSection(loggerFileCS);
va_list args;
va_start(args,pcFormat);
char acBuf[4096];
int nBuf = vsprintf(acBuf,pcFormat, args);
va_end(args);
fileLog(TRACE_FILE_NAME,acBuf);
#ifdef TRACE_CONSOLE
// write to the file
cout<<acBuf;
#endif //TRACE_CONSOLE
LeaveCriticalSection(loggerFileCS);
#endif //TRACE
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.