Writing debug information both in file and Windows debugger
-
Good day, colleagues!
How could I write debug info both to custom place (e. g. in file) and to default location (e. g. Windows debug console)?
Currently I use qInstallMsgHandler with this handler:
@void My_Message_Handler (QtMsgType message_type, const char * message) {
QString debug_string; switch (message_type) { case QtDebugMsg : debug_string = QString(message); break; ... QFile log_file (LOG_FILENAME); log_file.open (QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text); QTextStream text_stream (&log_file); text_stream << debug_string << '\n';
}@
What should I add to my code to write to the default debug output too?
-
Easiest way is to use a different logger than Qt's. QxtLogger comes to mind. That one can also easily integrate with Qt (register itself as the Qt Message handler), so your qDebug()'s still end up in your log file.
I requested a merge request for a logger engine I wrote for it for the Windows logger stream. I don't think it is in the 0.6 version (yet), but it should still be in the repo.
-
What we dot here in our custom logger is simply
std::cout<<debugString.toStdString();
in addition to writing to file.If stdout doesn't please you, you can use OutputDebugString
http://msdn.microsoft.com/en-us/library/aa363362(v=vs.85).aspx
to print in debug console[EDIT: fixed link formatting, Volker]