Writing debug information both in file and Windows debugger
-
wrote on 16 Mar 2011, 08:21 last edited by
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?
-
wrote on 16 Mar 2011, 08:27 last edited by
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.
-
wrote on 16 Mar 2011, 08:27 last edited by
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]
-
wrote on 16 Mar 2011, 08:28 last edited by
adding
CONFIG += consoleshould enable u to output messages to your windows console directly using qDebug() .. so on
-
wrote on 16 Mar 2011, 08:29 last edited by
[quote author="chetankjain" date="1300264091"]adding
CONFIG += consoleshould enable u to output messages to your windows console directly using qDebug() .. so on[/quote]
The windows console is not the same as the debugger stream.
1/5