March 16, 2011

usamytch usamytch
Lab Rat
37 posts

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:

  1. void My_Message_Handler (QtMsgType message_type, const char * message) {
  2.  
  3.     QString debug_string;
  4.    
  5.     switch (message_type) {
  6.     case QtDebugMsg : debug_string = QString(message);
  7.         break;
  8.     ...
  9.  
  10.     QFile log_file (LOG_FILENAME);
  11.     log_file.open (QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text);
  12.     QTextStream text_stream (&log_file);
  13.     text_stream << debug_string << '\n';
  14. }

What should I add to my code to write to the default debug output too?

4 replies

March 16, 2011

Andre Andre
Robot Herder
6396 posts

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.

March 16, 2011

florent.revelut florent.reve..
Lab Rat
103 posts

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]

March 16, 2011

Deleted Member # 4a2 Deleted Member # 4a2
Ant Farmer
1481 posts

adding
CONFIG += console

should enable u to output messages to your windows console directly using qDebug() .. so on

March 16, 2011

Andre Andre
Robot Herder
6396 posts

chetankjain wrote:
adding
CONFIG += console

should enable u to output messages to your windows console directly using qDebug() .. so on


The windows console is not the same as the debugger stream.

 
  ‹‹ [Plugin-Dev] invalid use of "::" when using non-Qt-namespace with QDebug      Shared OpenGL context with the OpenGL context of the application UI ››

You must log in to post a reply. Not a member yet? Register here!