author | hgs |
Thu, 10 Jun 2010 16:14:05 +0300 | |
changeset 44 | c2d07d913565 |
parent 43 | 99bcbff212ad |
child 47 | f83bd4ae1fe3 |
permissions | -rw-r--r-- |
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1 |
/* |
40 | 2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
3 |
* All rights reserved. |
|
4 |
* This component and the accompanying materials are made available |
|
5 |
* under the terms of "Eclipse Public License v1.0" |
|
6 |
* which accompanies this distribution, and is available |
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 |
* |
|
9 |
* Initial Contributors: |
|
10 |
* Nokia Corporation - initial contribution. |
|
11 |
* |
|
12 |
* Contributors: |
|
13 |
* |
|
14 |
* Description: |
|
15 |
* |
|
16 |
*/ |
|
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
17 |
|
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
18 |
#ifndef EMAILTRACE_H |
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
19 |
#define EMAILTRACE_H |
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
20 |
|
40 | 21 |
#include <e32debug.h> |
22 |
#include <qdebug.h> |
|
23 |
#include <qfile.h> |
|
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
24 |
|
40 | 25 |
/* |
44 | 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. |
|
40 | 30 |
*/ |
44 | 31 |
#ifndef NM_TRACING_SYSTEM |
32 |
#define NM_TRACING_SYSTEM 1 |
|
33 |
#endif |
|
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
34 |
|
44 | 35 |
/* |
36 |
* The macros NM_COMMENT_TRACES, NM_ERROR_TRACES, and NM_FUNCTION_TRACES |
|
37 |
* 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 |
|
39 |
* file is to be used in logging. The print_trace() helper function implements |
|
40 |
* printing. If NM_LOG_TO_FILE is zero or the NM_LOG_FILE cannot be opened, |
|
41 |
* the messages are printed to qDebug(). |
|
42 |
*/ |
|
43 |
#if NM_TRACING_SYSTEM && (defined(DEBUG) || defined(_DEBUG)) |
|
40 | 44 |
|
44 | 45 |
#define NM_COMMENT_TRACES 1 |
46 |
#define NM_ERROR_TRACES 1 |
|
47 |
#define NM_FUNCTION_TRACES 1 |
|
40 | 48 |
|
44 | 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" |
|
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
53 |
|
40 | 54 |
inline void print_trace(const QString& msg) |
55 |
{ |
|
44 | 56 |
static QFile file(NM_LOG_FILE); |
57 |
if (NM_LOG_TO_FILE && !file.isOpen()) { |
|
58 |
file.open(QIODevice::Append | QIODevice::Text); |
|
59 |
} |
|
60 |
if (file.isWritable()) { |
|
61 |
QDebug(&file).nospace() << "[Nmail] " << msg << '\n'; |
|
40 | 62 |
} else { |
44 | 63 |
qDebug().nospace() << "[Nmail] " << msg; |
40 | 64 |
} |
65 |
} |
|
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
66 |
|
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
67 |
#endif |
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
68 |
|
40 | 69 |
#endif /* DEBUG */ |
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
70 |
|
40 | 71 |
/* |
44 | 72 |
* The function NM_COMMENT() prints a debug message. The INFO macros and the |
43 | 73 |
* NMLOG macro are provided for legacy compatibility. They are deprecated and |
74 |
* should not be used. If sprintf() type of formatting is desired, consider |
|
75 |
* using QString::arg() or QTextStream. |
|
40 | 76 |
*/ |
44 | 77 |
#if NM_COMMENT_TRACES |
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
78 |
|
40 | 79 |
inline void NM_COMMENT(const QString& msg) |
80 |
{ |
|
81 |
print_trace("COMMENT : " + msg); |
|
82 |
} |
|
83 |
#define INFO(msg) NM_COMMENT(msg) |
|
84 |
#define INFO_1(msg,arg1)\ |
|
85 |
do {\ |
|
86 |
QString __msg;\ |
|
87 |
__msg.sprintf(msg,arg1);\ |
|
88 |
NM_COMMENT(__msg);\ |
|
89 |
} while (0) |
|
90 |
#define INFO_2(msg,arg1,arg2)\ |
|
91 |
do {\ |
|
92 |
QString __msg;\ |
|
93 |
__msg.sprintf(msg,arg1,arg2);\ |
|
94 |
NM_COMMENT(__msg);\ |
|
95 |
} while (0) |
|
96 |
#define INFO_3(msg,arg1,arg2,arg3)\ |
|
97 |
do {\ |
|
98 |
QString __msg;\ |
|
99 |
__msg.sprintf(msg,arg1,arg2,arg3);\ |
|
100 |
NM_COMMENT(__msg);\ |
|
101 |
} while (0) |
|
43 | 102 |
#define NMLOG(msg) NM_COMMENT(msg) |
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
103 |
|
40 | 104 |
#else |
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
105 |
|
40 | 106 |
#define NM_COMMENT(msg) |
107 |
#define INFO(msg) |
|
108 |
#define INFO_1(msg,arg1) |
|
109 |
#define INFO_2(msg,arg1,arg2) |
|
110 |
#define INFO_3(msg,arg1,arg2,arg3) |
|
43 | 111 |
#define NMLOG(msg) |
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
112 |
|
44 | 113 |
#endif /* NM_COMMENT_TRACES */ |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
114 |
|
40 | 115 |
/* |
116 |
* The function NM_ERROR() prints its second argument if the first argument |
|
117 |
* is non-zero. The ERROR macros are provided for legacy compatibility. They |
|
118 |
* are deprecated and should not be used. If sprintf() type of formatting is |
|
119 |
* desired, consider using QString::arg() or QTextStream. |
|
120 |
*/ |
|
44 | 121 |
#if NM_ERROR_TRACES |
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
122 |
|
40 | 123 |
inline void NM_ERROR(int err, const QString& msg) |
124 |
{ |
|
125 |
if (err) { |
|
126 |
print_trace("ERROR : " + msg); |
|
127 |
} |
|
128 |
} |
|
129 |
#define ERROR(err,msg) NM_ERROR(err,msg) |
|
130 |
#define ERROR_1(err,msg,arg1)\ |
|
131 |
do {\ |
|
132 |
QString __msg;\ |
|
133 |
__msg.sprintf(msg,arg1);\ |
|
134 |
NM_ERROR(err,__msg);\ |
|
135 |
} while (0) |
|
136 |
#define ERROR_2(err,msg,arg1,arg2)\ |
|
137 |
do {\ |
|
138 |
QString __msg;\ |
|
139 |
__msg.sprintf(msg,arg1,arg2);\ |
|
140 |
NM_ERROR(err,__msg);\ |
|
141 |
} while(0) |
|
142 |
#define ERROR_3(err,msg,arg1,arg2,arg3)\ |
|
143 |
do {\ |
|
144 |
QString __msg;\ |
|
145 |
__msg.sprintf(msg,arg1,srg2,arg3);\ |
|
146 |
NM_ERROR(err,__msg);\ |
|
147 |
} while(0) |
|
148 |
#define ERROR_GEN(msg) ERROR(KErrGeneral,msg) |
|
149 |
#define ERROR_GEN_1(msg,arg1) ERROR_1(KErrGeneral,msg,arg1) |
|
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
150 |
|
40 | 151 |
#else |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
152 |
|
40 | 153 |
#define NM_ERROR(err,msg) |
154 |
#define ERROR(err,msg) |
|
155 |
#define ERROR_1(err,msg,arg1) |
|
156 |
#define ERROR_2(err,msg,arg1,arg2) |
|
157 |
#define ERROR_3(err,msg,arg1,arg2,arg3) |
|
158 |
#define ERROR_GEN(msg) |
|
159 |
#define ERROR_GEN_1(msg,arg1) |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
160 |
|
44 | 161 |
#endif /* NM_ERROR_TRACES */ |
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
162 |
|
40 | 163 |
/* |
164 |
* The macro NM_FUNCTION, when used inside a function body, enables tracing |
|
44 | 165 |
* for a function. ENTER and RETURN messages are printed when entering into |
166 |
* and returning from a function, respectively. In case of an exception, |
|
167 |
* UNWIND (for stack unwinding) is printed. The FUNC_LOG macro is provided |
|
168 |
* for legacy compatibility. It is deprecated and should not be used. |
|
40 | 169 |
*/ |
44 | 170 |
#if NM_FUNCTION_TRACES |
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
171 |
|
40 | 172 |
class __ftracer |
173 |
{ |
|
174 |
public: |
|
175 |
__ftracer(const QString& _fn) |
|
176 |
: fn(_fn) |
|
177 |
{ |
|
178 |
print_trace("ENTER : " + fn); |
|
179 |
} |
|
180 |
~__ftracer() |
|
181 |
{ |
|
182 |
if (std::uncaught_exception()) { |
|
183 |
print_trace("UNWIND : " + fn); |
|
184 |
} else { |
|
185 |
print_trace("RETURN : " + fn); |
|
186 |
} |
|
187 |
} |
|
188 |
private: |
|
189 |
QString fn; |
|
190 |
}; |
|
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
191 |
|
43 | 192 |
#define NM_FUNCTION __ftracer __ft(__PRETTY_FUNCTION__) |
40 | 193 |
#define FUNC_LOG NM_FUNCTION |
194 |
||
195 |
#else |
|
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
196 |
|
40 | 197 |
#define NM_FUNCTION |
198 |
#define FUNC_LOG |
|
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
199 |
|
44 | 200 |
#endif /* NM_FUNCTION_TRACES */ |
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
201 |
|
40 | 202 |
#endif /* EMAILTRACE_H */ |