I have written a class to log messages in my application. The class has the options to either log to console, log to file or both.
A thread monitors a queue of strings, if the queue is empty. When I process a string to log to file:
if ( (blnOpen = clsDebugService::msFile.isOpen()) != true ) {
clsDebugService::msFile.open(QIODevice::WriteOnly | QIODevice::Text);
blnOpen = clsDebugService::msFile.isOpen();
}
if ( blnOpen == true ) {
QTextStream tsText(&clsDebugService::msFile);
tsText << strLine.toLatin1().data() << "\r\n";
}
This works perfectly and I can see that the information logged in the file is always complete, however when I do the following to output to the console:
if ( clsDebugService::msblnToConsole == true ) {
std::cout << strLine.toLatin1().data() << "\n";
std::cout << std::flush;
}
Sometimes, actually quite frequently the message displayed in the console isn't complete and is missing some characters from the end of the string. Originally I had the std::flush at the end of the same statement that sends the data to the console, this did the same, so I changed it to the above hoping that would fix it, it didn't.