المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Logger class -> write to file too slow



C++ Programming
07-01-2009, 06:00 PM
Hi there,

I built a logger class to trace and debug my programs.
Now I have very real-time dependent programs here and the problem is, when I activate the logger´s 'log to file'-option the program gets too slow to be run properly. But I want/need the logger to be active in normal operation, as well ... so that I can have a look at the output if something went wrong (like a crash).

The time stealer seems to be the opening and closing of the file for every log entry. But I cannot simply open it once and never close it, because the log entrys are only put into the file with the close() call.

This is the logger (which works otherwise fine). Any help with speeding it up, restructuring it or whatever needs to be done is appreciated. http://www.barakasoft.com/script/Forums/Images/smiley_smile.gif


Logger::Logger(void)
{
m_iLogLevel = DEBUG;
m_bToConsole = true;
m_bToFile = false;
m_sFilename = "tts_dump.out";
m_sPath = "./";
m_bFirstWriteToFile = true;
}

Logger::~Logger(void)
{}


Logger* Logger::GetInstance()
{
if( m_pLogger == NULL )
{
m_pLogger = new Logger();
}
return m_pLogger;
}

void Logger::Out( int level, const char* pcszFormat, ... )
{
va_list ap;
va_start( ap, pcszFormat );

if( m_bToConsole )
{
if( pcszFormat && level