Click here to Skip to main content
15,887,337 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: MFC CSocket class! [modified] Pin
Moak18-Jul-09 4:36
Moak18-Jul-09 4:36 
GeneralRe: MFC CSocket class! Pin
Hadi Dayvary18-Jul-09 5:14
professionalHadi Dayvary18-Jul-09 5:14 
QuestionChange dialog bg-color? Pin
bosfan1-Jul-09 3:35
bosfan1-Jul-09 3:35 
AnswerRe: Change dialog bg-color? Pin
SandipG 1-Jul-09 4:15
SandipG 1-Jul-09 4:15 
GeneralRe: Change dialog bg-color? [modified] Pin
bosfan1-Jul-09 4:35
bosfan1-Jul-09 4:35 
GeneralRe: Change dialog bg-color? Pin
«_Superman_»1-Jul-09 16:46
professional«_Superman_»1-Jul-09 16:46 
GeneralRe: Change dialog bg-color? Pin
bosfan1-Jul-09 21:33
bosfan1-Jul-09 21:33 
QuestionLogger class -> write to file too slow Pin
Souldrift1-Jul-09 3:30
Souldrift1-Jul-09 3:30 
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. Smile | :)

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 <= m_iLogLevel )
		{
			vprintf( pcszFormat, ap );
		}
	}
	
	if( m_bToFile )
	{
		if( pcszFormat && level <= m_iLogLevel )
		{
                	string loc = m_sPath;
			loc.append( m_sFilename );

			if( m_bFirstWriteToFile )
			{
				m_oFile.open(loc.c_str(), ios::out);
				m_bFirstWriteToFile = false;
			}
			else
			{
				m_oFile.open(loc.c_str(), ios::out|ios::app);
			}

			if( !m_oFile ) 
			{
				cerr << loc << " kann nicht geöffnet werden!\n";
			} 

			char buffer[1024];
			
			vsprintf_s( buffer, pcszFormat, ap );

			m_oFile << buffer;
			m_oFile.close();
		}
	}
	va_end( ap );
}

void Logger::SetLogLevel( int level )
{
	if( level >= 0 && level <= SYS_ERROR )
		m_iLogLevel = level;
}

void Logger::SetConsoleOutput( bool on )
{
	m_bToConsole = on;
}

void Logger::SetFileOutput( bool on, string filename, string path )
{
	m_bToFile = on;
}


Cheers

Souldrift
AnswerRe: Logger class -&gt; write to file too slow Pin
Stuart Dootson1-Jul-09 3:34
professionalStuart Dootson1-Jul-09 3:34 
AnswerRe: Logger class -&gt; write to file too slow Pin
Cedric Moonen1-Jul-09 3:35
Cedric Moonen1-Jul-09 3:35 
AnswerRe: Logger class -&gt; write to file too slow Pin
Michael Schubert1-Jul-09 4:01
Michael Schubert1-Jul-09 4:01 
AnswerRe: Logger class -&gt; write to file too slow Pin
David Crow1-Jul-09 4:52
David Crow1-Jul-09 4:52 
AnswerRe: Logger class -&gt; write to file too slow Pin
Joe Woodbury1-Jul-09 6:06
professionalJoe Woodbury1-Jul-09 6:06 
AnswerRe: Logger class -&gt; write to file too slow Pin
Chuck O'Toole1-Jul-09 10:31
Chuck O'Toole1-Jul-09 10:31 
GeneralRe: Logger class -&gt; write to file too slow Pin
Souldrift1-Jul-09 21:54
Souldrift1-Jul-09 21:54 
GeneralRe: Logger class -&gt; write to file too slow Pin
Michael Schubert1-Jul-09 23:25
Michael Schubert1-Jul-09 23:25 
Questionhow to detect Listctrl check box selection/deselection Pin
hemlat1-Jul-09 1:22
hemlat1-Jul-09 1:22 
AnswerRe: how to detect Listctrl check box selection/deselection Pin
Jijo.Raj1-Jul-09 1:45
Jijo.Raj1-Jul-09 1:45 
GeneralRe: how to detect Listctrl check box selection/deselection Pin
hemlat1-Jul-09 2:04
hemlat1-Jul-09 2:04 
GeneralRe: how to detect Listctrl check box selection/deselection Pin
Stuart Dootson1-Jul-09 2:40
professionalStuart Dootson1-Jul-09 2:40 
GeneralRe: how to detect Listctrl check box selection/deselection Pin
hemlat1-Jul-09 3:08
hemlat1-Jul-09 3:08 
GeneralRe: how to detect Listctrl check box selection/deselection Pin
CPallini1-Jul-09 3:21
mveCPallini1-Jul-09 3:21 
GeneralRe: how to detect Listctrl check box selection/deselection Pin
hemlat1-Jul-09 20:46
hemlat1-Jul-09 20:46 
GeneralRe: how to detect Listctrl check box selection/deselection Pin
Stuart Dootson1-Jul-09 3:31
professionalStuart Dootson1-Jul-09 3:31 
GeneralRe: how to detect Listctrl check box selection/deselection Pin
hemlat1-Jul-09 20:47
hemlat1-Jul-09 20:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.