emailservices/emaildebug/inc/emailtrace.h
changeset 56 15bc1d5d6267
parent 47 f83bd4ae1fe3
child 68 83cc6bae1de8
equal deleted inserted replaced
51:d845db10c0d4 56:15bc1d5d6267
    20 
    20 
    21 #include <QCoreApplication>
    21 #include <QCoreApplication>
    22 #include <QDebug>
    22 #include <QDebug>
    23 #include <QFile>
    23 #include <QFile>
    24 #include <QThread>
    24 #include <QThread>
       
    25 #include <QDateTime>
    25 
    26 
    26 /*
    27 /*
    27  * The macros NM_COMMENT_TRACES, NM_ERROR_TRACES, and NM_FUNCTION_TRACES
    28  * The macros NM_COMMENT_TRACES, NM_ERROR_TRACES, and NM_FUNCTION_TRACES
    28  * control which debug messages are printed. The trace logging is controlled
    29  * control which debug messages are printed. The trace logging is controlled
    29  * with the NM_LOG_TO_FILE macro, whereas the NM_LOG_DIRECTORY macro defines
    30  * with the NM_LOG_TO_FILE macro, whereas the NM_LOG_DIRECTORY macro defines
    31  * helper function implements printing. Log files are named according to
    32  * helper function implements printing. Log files are named according to
    32  * process and thread IDs. If NM_LOG_TO_FILE is zero or a log file cannot be
    33  * process and thread IDs. If NM_LOG_TO_FILE is zero or a log file cannot be
    33  * opened, the messages are printed to qDebug(). The DSC2STR() function can
    34  * opened, the messages are printed to qDebug(). The DSC2STR() function can
    34  * be used to convert Symbian descriptors to QString objects.
    35  * be used to convert Symbian descriptors to QString objects.
    35  */
    36  */
    36 #if defined(DEBUG) || defined(_DEBUG)
    37 #if defined(DEBUG) || defined(_DEBUG) || NM_COMMENT_TRACES || NM_ERROR_TRACES || NM_FUNCTION_TRACES
    37 
    38 
       
    39 #ifndef NM_COMMENT_TRACES
    38 #define NM_COMMENT_TRACES  0
    40 #define NM_COMMENT_TRACES  0
       
    41 #endif
       
    42 
       
    43 #ifndef NM_ERROR_TRACES
    39 #define NM_ERROR_TRACES    0
    44 #define NM_ERROR_TRACES    0
       
    45 #endif
       
    46 
       
    47 #ifndef NM_FUNCTION_TRACES
    40 #define NM_FUNCTION_TRACES 0
    48 #define NM_FUNCTION_TRACES 0
       
    49 #endif
    41 
    50 
    42 #if NM_COMMENT_TRACES || NM_ERROR_TRACES || NM_FUNCTION_TRACES
    51 #if NM_COMMENT_TRACES || NM_ERROR_TRACES || NM_FUNCTION_TRACES
    43 
    52 
    44 #define NM_LOG_TO_FILE   1
    53 #define NM_LOG_TO_FILE   1
    45 #define NM_LOG_DIRECTORY "c:/data/logs/"
    54 #define NM_LOG_DIRECTORY "c:/data/logs/"
    51                       arg(QCoreApplication::applicationPid()).
    60                       arg(QCoreApplication::applicationPid()).
    52                       arg(QThread::currentThreadId()));
    61                       arg(QThread::currentThreadId()));
    53     if (NM_LOG_TO_FILE && !file.isOpen()) {
    62     if (NM_LOG_TO_FILE && !file.isOpen()) {
    54         file.open(QIODevice::Append | QIODevice::Text);
    63         file.open(QIODevice::Append | QIODevice::Text);
    55     }
    64     }
       
    65     QDateTime dt = QDateTime::currentDateTime ();
    56     if (file.isWritable()) {
    66     if (file.isWritable()) {
    57         QDebug(&file).nospace() << msg << '\n';
    67         QDebug(&file).nospace() << dt.toString(Qt::ISODate) << " " << msg << '\n';
    58     } else {
    68     } else {
    59         qDebug().nospace() << "[Nmail] " << msg;
    69         qDebug().nospace() << "[Nmail] " << msg;
    60     }
    70     }
    61 }
    71 }
    62 
    72