emailservices/emaildebug/inc/emailtrace.h
changeset 44 c2d07d913565
parent 43 99bcbff212ad
child 47 f83bd4ae1fe3
equal deleted inserted replaced
43:99bcbff212ad 44:c2d07d913565
    21 #include <e32debug.h>
    21 #include <e32debug.h>
    22 #include <qdebug.h>
    22 #include <qdebug.h>
    23 #include <qfile.h>
    23 #include <qfile.h>
    24 
    24 
    25 /*
    25 /*
    26  * The macros COMMENT_TRACES, ERROR_TRACES, and FUNCTION_TRACES control which
    26  * The NM_TRACING_SYSTEM macro can be used to enable and disable the tracing
    27  * trace messages are printed. The trace message logging is controlled with
    27  * system in debug mode. The tracing system can be disabled in a specific
    28  * the LOG_TO_FILE macro, whereas the LOG_FILE macro defines which file is to
    28  * source file by defining the macro "NM_TRACING_SYSTEM 0" before this file
    29  * be used in logging. The print_trace() helper function implements printing.
    29  * is included.
    30  * If LOG_TO_FILE is zero or the LOG_FILE cannot be opened, the messages are
    30  */
    31  * printed to qDebug().
    31 #ifndef NM_TRACING_SYSTEM
    32  */
    32 #define NM_TRACING_SYSTEM 1
    33 #if defined(DEBUG) || defined(_DEBUG)
    33 #endif
    34 
    34 
    35 #define COMMENT_TRACES  1
    35 /*
    36 #define ERROR_TRACES    1
    36  * The macros NM_COMMENT_TRACES, NM_ERROR_TRACES, and NM_FUNCTION_TRACES
    37 #define FUNCTION_TRACES 1
    37  * control which debug messages are printed. The trace logging is controlled
    38 
    38  * with the NM_LOG_TO_FILE macro, whereas the NM_LOG_FILE macro defines which
    39 #if COMMENT_TRACES || ERROR_TRACES || FUNCTION_TRACES
    39  * file is to be used in logging. The print_trace() helper function implements
    40 
    40  * printing. If NM_LOG_TO_FILE is zero or the NM_LOG_FILE cannot be opened,
    41 #define LOG_TO_FILE     0
    41  * the messages are printed to qDebug().
    42 #define LOG_FILE        "c:/logs/nmail_trace.log"
    42  */
       
    43 #if NM_TRACING_SYSTEM && (defined(DEBUG) || defined(_DEBUG))
       
    44 
       
    45 #define NM_COMMENT_TRACES  1
       
    46 #define NM_ERROR_TRACES    1
       
    47 #define NM_FUNCTION_TRACES 1
       
    48 
       
    49 #if NM_COMMENT_TRACES || NM_ERROR_TRACES || NM_FUNCTION_TRACES
       
    50 
       
    51 #define NM_LOG_TO_FILE 0
       
    52 #define NM_LOG_FILE    "c:/data/logs/nmail_trace.log"
    43 
    53 
    44 inline void print_trace(const QString& msg)
    54 inline void print_trace(const QString& msg)
    45 {
    55 {
    46     QFile out(LOG_FILE);
    56     static QFile file(NM_LOG_FILE);
    47     if (LOG_TO_FILE && out.open(QIODevice::Append | QIODevice::Text)) {
    57     if (NM_LOG_TO_FILE && !file.isOpen()) {
    48         QDebug(&out) << "[Nmail]" << msg;
    58         file.open(QIODevice::Append | QIODevice::Text);
    49         out.putChar('\n');
    59     }
    50         out.close();
    60     if (file.isWritable()) {
       
    61         QDebug(&file).nospace() << "[Nmail] " << msg << '\n';
    51     } else {
    62     } else {
    52         qDebug() << "[Nmail]" << msg;
    63         qDebug().nospace() << "[Nmail] " << msg;
    53     }
    64     }
    54 }
    65 }
    55 
    66 
    56 #endif
    67 #endif
    57 
    68 
    58 #endif /* DEBUG */
    69 #endif /* DEBUG */
    59 
    70 
    60 /*
    71 /*
    61  * The function NM_COMMENT() prints a trace message. The INFO macros and the
    72  * The function NM_COMMENT() prints a debug message. The INFO macros and the
    62  * NMLOG macro are provided for legacy compatibility. They are deprecated and
    73  * NMLOG macro are provided for legacy compatibility. They are deprecated and
    63  * should not be used. If sprintf() type of formatting is desired, consider
    74  * should not be used. If sprintf() type of formatting is desired, consider
    64  * using QString::arg() or QTextStream.
    75  * using QString::arg() or QTextStream.
    65  */
    76  */
    66 #if COMMENT_TRACES
    77 #if NM_COMMENT_TRACES
    67 
    78 
    68 inline void NM_COMMENT(const QString& msg)
    79 inline void NM_COMMENT(const QString& msg)
    69 {
    80 {
    70     print_trace("COMMENT : " + msg);
    81     print_trace("COMMENT : " + msg);
    71 }
    82 }
    97 #define INFO_1(msg,arg1)
   108 #define INFO_1(msg,arg1)
    98 #define INFO_2(msg,arg1,arg2)
   109 #define INFO_2(msg,arg1,arg2)
    99 #define INFO_3(msg,arg1,arg2,arg3)
   110 #define INFO_3(msg,arg1,arg2,arg3)
   100 #define NMLOG(msg)
   111 #define NMLOG(msg)
   101 
   112 
   102 #endif /* COMMENT_TRACES */
   113 #endif /* NM_COMMENT_TRACES */
   103 
   114 
   104 /*
   115 /*
   105  * The function NM_ERROR() prints its second argument if the first argument
   116  * The function NM_ERROR() prints its second argument if the first argument
   106  * is non-zero. The ERROR macros are provided for legacy compatibility. They
   117  * is non-zero. The ERROR macros are provided for legacy compatibility. They
   107  * are deprecated and should not be used. If sprintf() type of formatting is
   118  * are deprecated and should not be used. If sprintf() type of formatting is
   108  * desired, consider using QString::arg() or QTextStream.
   119  * desired, consider using QString::arg() or QTextStream.
   109  */
   120  */
   110 #if ERROR_TRACES
   121 #if NM_ERROR_TRACES
   111 
   122 
   112 inline void NM_ERROR(int err, const QString& msg)
   123 inline void NM_ERROR(int err, const QString& msg)
   113 {
   124 {
   114     if (err) {
   125     if (err) {
   115         print_trace("ERROR : " + msg);
   126         print_trace("ERROR : " + msg);
   145 #define ERROR_2(err,msg,arg1,arg2)
   156 #define ERROR_2(err,msg,arg1,arg2)
   146 #define ERROR_3(err,msg,arg1,arg2,arg3)
   157 #define ERROR_3(err,msg,arg1,arg2,arg3)
   147 #define ERROR_GEN(msg)
   158 #define ERROR_GEN(msg)
   148 #define ERROR_GEN_1(msg,arg1)
   159 #define ERROR_GEN_1(msg,arg1)
   149 
   160 
   150 #endif /* ERROR_TRACES */
   161 #endif /* NM_ERROR_TRACES */
   151 
   162 
   152 /*
   163 /*
   153  * The macro NM_FUNCTION, when used inside a function body, enables tracing
   164  * The macro NM_FUNCTION, when used inside a function body, enables tracing
   154  * for a function. Trace messages with labels ENTER and RETURN are printed
   165  * for a function. ENTER and RETURN messages are printed when entering into
   155  * when entering into and returning from a function, respectively. In case of
   166  * and returning from a function, respectively. In case of an exception,
   156  * an exception or a Symbian leave, a message with label UNWIND is printed
   167  * UNWIND (for stack unwinding) is printed. The FUNC_LOG macro is provided
   157  * (UNWIND stands for stack unwinding). The FUNC_LOG macro is provided for
   168  * for legacy compatibility. It is deprecated and should not be used.
   158  * legacy compatibility. It is deprecated and should not be used.
   169  */
   159  */
   170 #if NM_FUNCTION_TRACES
   160 #if FUNCTION_TRACES
       
   161 
   171 
   162 class __ftracer
   172 class __ftracer
   163 {
   173 {
   164 public:
   174 public:
   165     __ftracer(const QString& _fn)
   175     __ftracer(const QString& _fn)
   185 #else
   195 #else
   186 
   196 
   187 #define NM_FUNCTION
   197 #define NM_FUNCTION
   188 #define FUNC_LOG
   198 #define FUNC_LOG
   189 
   199 
   190 #endif /* FUNCTION TRACES */
   200 #endif /* NM_FUNCTION_TRACES */
   191 
   201 
   192 #endif /* EMAILTRACE_H */
   202 #endif /* EMAILTRACE_H */