inc/cntdebug.h
changeset 50 77bc263e1626
parent 46 efe85016a067
child 53 e6aff7b69165
equal deleted inserted replaced
49:74b30151afd6 50:77bc263e1626
    21 
    21 
    22 #include <QDebug>   // QDebug
    22 #include <QDebug>   // QDebug
    23 #include <QtGlobal> // qDebug()
    23 #include <QtGlobal> // qDebug()
    24 
    24 
    25 // #define TRACK_MEMORY_LEAKS
    25 // #define TRACK_MEMORY_LEAKS
       
    26 // #define CNT_TRACE2FILE
    26 
    27 
    27 /*!
    28 /*!
    28     \def CNT_UNUSED(name)
    29     \def CNT_UNUSED(name)
    29     \brief Declares a single variable as unused when tracing is disabled.
    30     \brief Declares a single variable as unused when tracing is disabled.
    30 
    31 
   347 
   348 
   348     \param args Any number of arguments that can be streamed into a QTextStream, joined together
   349     \param args Any number of arguments that can be streamed into a QTextStream, joined together
   349     by the streaming operator <<.
   350     by the streaming operator <<.
   350 */
   351 */
   351 
   352 
   352 
   353 #if defined (_DEBUG) || defined (CNT_TRACE2FILE)
   353 #ifdef _DEBUG
       
   354     #define CNT_UNUSED(name)
   354     #define CNT_UNUSED(name)
   355     #define CNT_STATIC_ENTRY qDebug() << __PRETTY_FUNCTION__ << "entry";
   355     #define CNT_STATIC_ENTRY qDebug() << __PRETTY_FUNCTION__ << "entry";
   356     #define CNT_STATIC_ENTRY_ARGS(args) qDebug() << __PRETTY_FUNCTION__ << "entry," << args;
   356     #define CNT_STATIC_ENTRY_ARGS(args) qDebug() << __PRETTY_FUNCTION__ << "entry," << args;
   357     #define CNT_ENTRY qDebug() << __PRETTY_FUNCTION__ << "this" << (void *)this << "entry";
   357     #define CNT_ENTRY qDebug() << __PRETTY_FUNCTION__ << "this" << (void *)this << "entry";
   358     #define CNT_ENTRY_ARGS(args) qDebug() << __PRETTY_FUNCTION__ << "this" << (void *)this << "entry," << args;
   358     #define CNT_ENTRY_ARGS(args) qDebug() << __PRETTY_FUNCTION__ << "this" << (void *)this << "entry," << args;
   359     #define CNT_EXIT qDebug() << __PRETTY_FUNCTION__ << "exit";
   359     #define CNT_EXIT qDebug() << __PRETTY_FUNCTION__ << "exit";
   360     #define CNT_EXIT_ARGS(args) qDebug() << __PRETTY_FUNCTION__ << "exit," << args;
   360     #define CNT_EXIT_ARGS(args) qDebug() << __PRETTY_FUNCTION__ << "exit," << args;
   361     #define CNT_LOG qDebug() << __PRETTY_FUNCTION__ << "this" << (void *)this;
   361     #define CNT_LOG qDebug() << __PRETTY_FUNCTION__ << "this" << (void *)this;
   362     #define CNT_LOG_ARGS(args) qDebug() << __PRETTY_FUNCTION__ << args;
   362     #define CNT_LOG_ARGS(args) qDebug() << __PRETTY_FUNCTION__ << args;
       
   363     #define CNT_WARNING(args) qWarning() << __PRETTY_FUNCTION__ << args;
       
   364     #define CNT_CRITICAL(args) qCritical() << __PRETTY_FUNCTION__ << args;
       
   365     #define CNT_FATAL(args) qFatal() << __PRETTY_FUNCTION__ << args;
   363 #else
   366 #else
   364     #define CNT_UNUSED(name) Q_UNUSED(name)
   367     #define CNT_UNUSED(name) Q_UNUSED(name)
   365     #define CNT_STATIC_ENTRY
   368     #define CNT_STATIC_ENTRY
   366     #define CNT_STATIC_ENTRY_ARGS(args)
   369     #define CNT_STATIC_ENTRY_ARGS(args)
   367     #define CNT_ENTRY
   370     #define CNT_ENTRY
   368     #define CNT_ENTRY_ARGS(args)
   371     #define CNT_ENTRY_ARGS(args)
   369     #define CNT_EXIT
   372     #define CNT_EXIT
   370     #define CNT_EXIT_ARGS(args)
   373     #define CNT_EXIT_ARGS(args)
   371     #define CNT_LOG
   374     #define CNT_LOG
   372     #define CNT_LOG_ARGS(args)
   375     #define CNT_LOG_ARGS(args)
   373 #endif // _DEBUG
   376     #define CNT_WARNING(args)
   374 
   377     #define CNT_CRITICAL(args)
       
   378     #define CNT_FATAL(args)
       
   379 #endif // _DEBUG || CNT_TRACE2FILE
       
   380     
   375 // for tracing memory leaks
   381 // for tracing memory leaks
   376 #ifdef TRACK_MEMORY_LEAKS
   382 #ifdef TRACK_MEMORY_LEAKS
   377     #include <hbapplication.h>
   383     #include <hbapplication.h>
   378 
   384 
   379     #define CNT_TRACK_QOBJECTLIFE(obj) { new CntQObjectTracker(obj, __FILE__, __LINE__); }
   385     #define CNT_TRACK_QOBJECTLIFE(obj) { new CntQObjectTracker(obj, __FILE__, __LINE__); }
   404 #else
   410 #else
   405     #define CNT_TRACK_QOBJECTLIFE(obj)
   411     #define CNT_TRACK_QOBJECTLIFE(obj)
   406     #define CNT_TRACK_QOBJECTLIVES(obj)
   412     #define CNT_TRACK_QOBJECTLIVES(obj)
   407 #endif
   413 #endif
   408 
   414 
       
   415 // filter phonebook app traces
       
   416 #ifdef CNT_TRACE2FILE
       
   417     #include <QFile>
       
   418     #include <QTextStream>
       
   419     static void cntCustomLog2File(QtMsgType type, const char *msg)
       
   420     {   
       
   421         QFile logFile("c:/cnt_logs.log");
       
   422         if (!logFile.open(QIODevice::Append | QIODevice::Text))
       
   423         {
       
   424             qFatal("error opening c:/cnt_logs.log file");
       
   425             return;
       
   426         }
       
   427 
       
   428         QTextStream out(&logFile);
       
   429         switch (type)
       
   430         {
       
   431             case QtDebugMsg:
       
   432                 out << "[CNT] Debug: " << msg;
       
   433                 break;
       
   434             case QtWarningMsg:
       
   435                 out << "[CNT] Warning: " << msg;
       
   436                 break;
       
   437             case QtCriticalMsg:
       
   438                 out << "[CNT] Critical: " << msg;
       
   439                 break;
       
   440             case QtFatalMsg:
       
   441                 out << "[CNT] Fatal: " << msg;
       
   442                 abort();
       
   443                 break;
       
   444             default:
       
   445                 out << "[CNT] No Log Selection Type: " << msg;
       
   446                 break;
       
   447         }
       
   448     }
       
   449     #define MSG_HANDLER cntCustomLog2File
       
   450 #else
       
   451     #ifdef Q_OS_SYMBIAN
       
   452         #include <e32debug.h>
       
   453         static void cntCustomLog(QtMsgType type, const char *msg)
       
   454         {
       
   455             switch (type) {
       
   456                 case QtDebugMsg:
       
   457                     RDebug::Printf("[CNT] Debug: %s\n", msg);
       
   458                     break;
       
   459                 case QtWarningMsg:
       
   460                     RDebug::Printf("[CNT] Warning: %s\n", msg);
       
   461                     break;
       
   462                 case QtCriticalMsg:
       
   463                     RDebug::Printf("[CNT] Critical: %s\n", msg);
       
   464                     break;
       
   465                 case QtFatalMsg:
       
   466                     RDebug::Printf("[CNT] Fatal: %s\n", msg);
       
   467                     abort();
       
   468                     break;
       
   469                 default:
       
   470                     break;
       
   471             }
       
   472         }
       
   473         #define MSG_HANDLER cntCustomLog
       
   474     #else
       
   475         #define MSG_HANDLER 0
       
   476     #endif  // Q_OS_SYMBIAN
       
   477 #endif  // CNT_TRACE2FILE
       
   478 
   409 #endif // CNTDEBUG_H
   479 #endif // CNTDEBUG_H