16 */ |
16 */ |
17 |
17 |
18 #ifndef EMAILTRACE_H |
18 #ifndef EMAILTRACE_H |
19 #define EMAILTRACE_H |
19 #define EMAILTRACE_H |
20 |
20 |
21 #include <e32debug.h> |
21 #include <QCoreApplication> |
22 #include <qdebug.h> |
22 #include <QDebug> |
23 #include <qfile.h> |
23 #include <QFile> |
24 |
24 #include <QThread> |
25 /* |
|
26 * The NM_TRACING_SYSTEM macro can be used to enable and disable the tracing |
|
27 * system in debug mode. The tracing system can be disabled in a specific |
|
28 * source file by defining the macro "NM_TRACING_SYSTEM 0" before this file |
|
29 * is included. |
|
30 */ |
|
31 #ifndef NM_TRACING_SYSTEM |
|
32 #define NM_TRACING_SYSTEM 1 |
|
33 #endif |
|
34 |
25 |
35 /* |
26 /* |
36 * The macros NM_COMMENT_TRACES, NM_ERROR_TRACES, and NM_FUNCTION_TRACES |
27 * The macros NM_COMMENT_TRACES, NM_ERROR_TRACES, and NM_FUNCTION_TRACES |
37 * control which debug messages are printed. The trace logging is controlled |
28 * control which debug messages are printed. The trace logging is controlled |
38 * with the NM_LOG_TO_FILE macro, whereas the NM_LOG_FILE macro defines which |
29 * with the NM_LOG_TO_FILE macro, whereas the NM_LOG_DIRECTORY macro defines |
39 * file is to be used in logging. The print_trace() helper function implements |
30 * which directory is to be used to store the log files. The print_trace() |
40 * printing. If NM_LOG_TO_FILE is zero or the NM_LOG_FILE cannot be opened, |
31 * helper function implements printing. Log files are named according to |
41 * the messages are printed to qDebug(). |
32 * process and thread IDs. If NM_LOG_TO_FILE is zero or a log file cannot be |
42 */ |
33 * opened, the messages are printed to qDebug(). The DSC2STR() function can |
43 #if NM_TRACING_SYSTEM && (defined(DEBUG) || defined(_DEBUG)) |
34 * be used to convert Symbian descriptors to QString objects. |
44 |
35 */ |
45 #define NM_COMMENT_TRACES 1 |
36 #if defined(DEBUG) || defined(_DEBUG) |
46 #define NM_ERROR_TRACES 1 |
37 |
47 #define NM_FUNCTION_TRACES 1 |
38 #define NM_COMMENT_TRACES 0 |
|
39 #define NM_ERROR_TRACES 0 |
|
40 #define NM_FUNCTION_TRACES 0 |
48 |
41 |
49 #if NM_COMMENT_TRACES || NM_ERROR_TRACES || NM_FUNCTION_TRACES |
42 #if NM_COMMENT_TRACES || NM_ERROR_TRACES || NM_FUNCTION_TRACES |
50 |
43 |
51 #define NM_LOG_TO_FILE 0 |
44 #define NM_LOG_TO_FILE 1 |
52 #define NM_LOG_FILE "c:/data/logs/nmail_trace.log" |
45 #define NM_LOG_DIRECTORY "c:/data/logs/" |
53 |
46 |
54 inline void print_trace(const QString& msg) |
47 inline void print_trace(const QString& msg) |
55 { |
48 { |
56 static QFile file(NM_LOG_FILE); |
49 static QFile file(NM_LOG_DIRECTORY+ |
|
50 QString("nmail_p%1_t%2.log"). |
|
51 arg(QCoreApplication::applicationPid()). |
|
52 arg(QThread::currentThreadId())); |
57 if (NM_LOG_TO_FILE && !file.isOpen()) { |
53 if (NM_LOG_TO_FILE && !file.isOpen()) { |
58 file.open(QIODevice::Append | QIODevice::Text); |
54 file.open(QIODevice::Append | QIODevice::Text); |
59 } |
55 } |
60 if (file.isWritable()) { |
56 if (file.isWritable()) { |
61 QDebug(&file).nospace() << "[Nmail] " << msg << '\n'; |
57 QDebug(&file).nospace() << msg << '\n'; |
62 } else { |
58 } else { |
63 qDebug().nospace() << "[Nmail] " << msg; |
59 qDebug().nospace() << "[Nmail] " << msg; |
64 } |
60 } |
65 } |
61 } |
66 |
62 |
67 #endif |
63 #endif |
|
64 |
|
65 inline QString DSC2STR(const TDesC& dsc) |
|
66 { |
|
67 return QString::fromRawData(reinterpret_cast<const QChar*>(dsc.Ptr()), |
|
68 dsc.Length()); |
|
69 } |
|
70 |
|
71 #else |
|
72 |
|
73 #define DSC2STR(dsc) |
68 |
74 |
69 #endif /* DEBUG */ |
75 #endif /* DEBUG */ |
70 |
76 |
71 /* |
77 /* |
72 * The function NM_COMMENT() prints a debug message. The INFO macros and the |
78 * The function NM_COMMENT() prints a debug message. The INFO macros and the |
140 NM_ERROR(err,__msg);\ |
146 NM_ERROR(err,__msg);\ |
141 } while(0) |
147 } while(0) |
142 #define ERROR_3(err,msg,arg1,arg2,arg3)\ |
148 #define ERROR_3(err,msg,arg1,arg2,arg3)\ |
143 do {\ |
149 do {\ |
144 QString __msg;\ |
150 QString __msg;\ |
145 __msg.sprintf(msg,arg1,srg2,arg3);\ |
151 __msg.sprintf(msg,arg1,arg2,arg3);\ |
146 NM_ERROR(err,__msg);\ |
152 NM_ERROR(err,__msg);\ |
147 } while(0) |
153 } while(0) |
148 #define ERROR_GEN(msg) ERROR(KErrGeneral,msg) |
154 #define ERROR_GEN(msg) ERROR(KErrGeneral,msg) |
149 #define ERROR_GEN_1(msg,arg1) ERROR_1(KErrGeneral,msg,arg1) |
155 #define ERROR_GEN_1(msg,arg1) ERROR_1(KErrGeneral,msg,arg1) |
150 |
156 |
160 |
166 |
161 #endif /* NM_ERROR_TRACES */ |
167 #endif /* NM_ERROR_TRACES */ |
162 |
168 |
163 /* |
169 /* |
164 * The macro NM_FUNCTION, when used inside a function body, enables tracing |
170 * The macro NM_FUNCTION, when used inside a function body, enables tracing |
165 * for a function. ENTER and RETURN messages are printed when entering into |
171 * for a function. If used, it should be placed on the first line of the |
|
172 * function body. ENTER and RETURN messages are printed when entering into |
166 * and returning from a function, respectively. In case of an exception, |
173 * and returning from a function, respectively. In case of an exception, |
167 * UNWIND (for stack unwinding) is printed. The FUNC_LOG macro is provided |
174 * UNWIND (for stack unwinding) is printed instead of RETURN. The FUNC_LOG |
168 * for legacy compatibility. It is deprecated and should not be used. |
175 * macro is provided for legacy compatibility. It is deprecated and should |
|
176 * not be used. |
169 */ |
177 */ |
170 #if NM_FUNCTION_TRACES |
178 #if NM_FUNCTION_TRACES |
171 |
179 |
172 class __ftracer |
180 class __ftracer |
173 { |
181 { |