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

C / C++ / MFC

 
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 
AnswerRe: Logger class -> write to file too slow Pin
Stuart Dootson1-Jul-09 3:34
professionalStuart Dootson1-Jul-09 3:34 
AnswerRe: Logger class -> write to file too slow Pin
Cedric Moonen1-Jul-09 3:35
Cedric Moonen1-Jul-09 3:35 
AnswerRe: Logger class -> write to file too slow Pin
Michael Schubert1-Jul-09 4:01
Michael Schubert1-Jul-09 4:01 
AnswerRe: Logger class -> write to file too slow Pin
David Crow1-Jul-09 4:52
David Crow1-Jul-09 4:52 
AnswerRe: Logger class -> write to file too slow Pin
Joe Woodbury1-Jul-09 6:06
professionalJoe Woodbury1-Jul-09 6:06 
AnswerRe: Logger class -> write to file too slow Pin
Chuck O'Toole1-Jul-09 10:31
Chuck O'Toole1-Jul-09 10:31 
The bad news is that if you are using a Logger Class to dump output somewhere in case your program crashes, then Open / Append / Close is the only way to make sure that critical "trace" messages are not left in memory at the crash. All the other suggestions, buffering, asynch I/O, can improve the speed at the expense of the exact reason to have a logger for debug tracing.

Bite the bullet and live with the slower code. Here's what I use which includes a timestamp in the output, modify it as you see fit. Also, since this is in a class derived from a synchornized object (which has a Lock/Unlock function), this is threadsafe.
// Add a line of text to the Log
void Logger::LogThis(CString Text)
{
    SYSTEMTIME cur_time;
	CString t1;
	CString t2;
	DWORD dwBytesWritten;

	if (Folder.IsEmpty() || Prefix.IsEmpty())
	{
		TRACE("Log Location Not Set");
		return;
	}
	Lock();													// force single file to the log file
    GetLocalTime(&cur_time);
	t1.Format("%02d-%02d-%04d %02d:%02d:%02d : %.200s\r\n",
		      cur_time.wMonth, cur_time.wDay, cur_time.wYear,
		      cur_time.wHour, cur_time.wMinute, cur_time.wSecond, Text);
	t2.Format("%s%s%04d%02d%02d.log", Folder, Prefix, cur_time.wYear, cur_time.wMonth, cur_time.wDay);
	HANDLE hAppend = CreateFile(t2,	// open log file
			FILE_APPEND_DATA,		// open for writing
			FILE_SHARE_READ,		// allow multiple readers
			NULL,				// no security
			OPEN_ALWAYS,			// open or create
			FILE_ATTRIBUTE_NORMAL,	// normal file
			NULL);				// no attr. template
	if (hAppend != INVALID_HANDLE_VALUE)
	{
		SetFilePointer(hAppend, 0, NULL, FILE_END);
		WriteFile(hAppend, (LPCTSTR)t1, t1.GetLength(), &dwBytesWritten, NULL);
		CloseHandle(hAppend);
	}
	Unlock();												// OK, file is ready for the next guy
}

And it's created with:
TheLogFile = new Logger();
TheLogFile->SetFolder("Log\\");
TheLogFile->SetPrefix("UpdateProcess");

GeneralRe: Logger class -> write to file too slow Pin
Souldrift1-Jul-09 21:54
Souldrift1-Jul-09 21:54 
GeneralRe: Logger class -> 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 
Questionabstract class Pin
MozhdehQeraati1-Jul-09 0:31
MozhdehQeraati1-Jul-09 0:31 
AnswerRe: abstract class Pin
Stuart Dootson1-Jul-09 0:46
professionalStuart Dootson1-Jul-09 0:46 
AnswerRe: abstract class Pin
ochsenmeier marc1-Jul-09 0:51
ochsenmeier marc1-Jul-09 0:51 
QuestionDebug Assertion Failed in atlcomcli.h. Pin
Le@rner30-Jun-09 21:20
Le@rner30-Jun-09 21:20 
AnswerRe: Debug Assertion Failed in atlcomcli.h. Pin
KarstenK30-Jun-09 21:33
mveKarstenK30-Jun-09 21:33 
GeneralRe: Debug Assertion Failed in atlcomcli.h. Pin
Le@rner30-Jun-09 21:37
Le@rner30-Jun-09 21:37 

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.