author | hgs |
Fri, 23 Jul 2010 19:09:50 +0300 | |
changeset 56 | 15bc1d5d6267 |
parent 47 | f83bd4ae1fe3 |
child 68 | 83cc6bae1de8 |
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 |
|
47 | 21 |
#include <QCoreApplication> |
22 |
#include <QDebug> |
|
23 |
#include <QFile> |
|
24 |
#include <QThread> |
|
56 | 25 |
#include <QDateTime> |
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
26 |
|
44 | 27 |
/* |
28 |
* The macros NM_COMMENT_TRACES, NM_ERROR_TRACES, and NM_FUNCTION_TRACES |
|
29 |
* control which debug messages are printed. The trace logging is controlled |
|
47 | 30 |
* with the NM_LOG_TO_FILE macro, whereas the NM_LOG_DIRECTORY macro defines |
31 |
* which directory is to be used to store the log files. The print_trace() |
|
32 |
* helper function implements printing. Log files are named according to |
|
33 |
* process and thread IDs. If NM_LOG_TO_FILE is zero or a log file cannot be |
|
34 |
* opened, the messages are printed to qDebug(). The DSC2STR() function can |
|
35 |
* be used to convert Symbian descriptors to QString objects. |
|
44 | 36 |
*/ |
56 | 37 |
#if defined(DEBUG) || defined(_DEBUG) || NM_COMMENT_TRACES || NM_ERROR_TRACES || NM_FUNCTION_TRACES |
40 | 38 |
|
56 | 39 |
#ifndef NM_COMMENT_TRACES |
47 | 40 |
#define NM_COMMENT_TRACES 0 |
56 | 41 |
#endif |
42 |
||
43 |
#ifndef NM_ERROR_TRACES |
|
47 | 44 |
#define NM_ERROR_TRACES 0 |
56 | 45 |
#endif |
46 |
||
47 |
#ifndef NM_FUNCTION_TRACES |
|
47 | 48 |
#define NM_FUNCTION_TRACES 0 |
56 | 49 |
#endif |
40 | 50 |
|
44 | 51 |
#if NM_COMMENT_TRACES || NM_ERROR_TRACES || NM_FUNCTION_TRACES |
52 |
||
47 | 53 |
#define NM_LOG_TO_FILE 1 |
54 |
#define NM_LOG_DIRECTORY "c:/data/logs/" |
|
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
55 |
|
40 | 56 |
inline void print_trace(const QString& msg) |
57 |
{ |
|
47 | 58 |
static QFile file(NM_LOG_DIRECTORY+ |
59 |
QString("nmail_p%1_t%2.log"). |
|
60 |
arg(QCoreApplication::applicationPid()). |
|
61 |
arg(QThread::currentThreadId())); |
|
44 | 62 |
if (NM_LOG_TO_FILE && !file.isOpen()) { |
63 |
file.open(QIODevice::Append | QIODevice::Text); |
|
64 |
} |
|
56 | 65 |
QDateTime dt = QDateTime::currentDateTime (); |
44 | 66 |
if (file.isWritable()) { |
56 | 67 |
QDebug(&file).nospace() << dt.toString(Qt::ISODate) << " " << msg << '\n'; |
40 | 68 |
} else { |
44 | 69 |
qDebug().nospace() << "[Nmail] " << msg; |
40 | 70 |
} |
71 |
} |
|
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
72 |
|
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
73 |
#endif |
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
74 |
|
47 | 75 |
inline QString DSC2STR(const TDesC& dsc) |
76 |
{ |
|
77 |
return QString::fromRawData(reinterpret_cast<const QChar*>(dsc.Ptr()), |
|
78 |
dsc.Length()); |
|
79 |
} |
|
80 |
||
81 |
#else |
|
82 |
||
83 |
#define DSC2STR(dsc) |
|
84 |
||
40 | 85 |
#endif /* DEBUG */ |
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
86 |
|
40 | 87 |
/* |
44 | 88 |
* The function NM_COMMENT() prints a debug message. The INFO macros and the |
43 | 89 |
* NMLOG macro are provided for legacy compatibility. They are deprecated and |
90 |
* should not be used. If sprintf() type of formatting is desired, consider |
|
91 |
* using QString::arg() or QTextStream. |
|
40 | 92 |
*/ |
44 | 93 |
#if NM_COMMENT_TRACES |
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
94 |
|
40 | 95 |
inline void NM_COMMENT(const QString& msg) |
96 |
{ |
|
97 |
print_trace("COMMENT : " + msg); |
|
98 |
} |
|
99 |
#define INFO(msg) NM_COMMENT(msg) |
|
100 |
#define INFO_1(msg,arg1)\ |
|
101 |
do {\ |
|
102 |
QString __msg;\ |
|
103 |
__msg.sprintf(msg,arg1);\ |
|
104 |
NM_COMMENT(__msg);\ |
|
105 |
} while (0) |
|
106 |
#define INFO_2(msg,arg1,arg2)\ |
|
107 |
do {\ |
|
108 |
QString __msg;\ |
|
109 |
__msg.sprintf(msg,arg1,arg2);\ |
|
110 |
NM_COMMENT(__msg);\ |
|
111 |
} while (0) |
|
112 |
#define INFO_3(msg,arg1,arg2,arg3)\ |
|
113 |
do {\ |
|
114 |
QString __msg;\ |
|
115 |
__msg.sprintf(msg,arg1,arg2,arg3);\ |
|
116 |
NM_COMMENT(__msg);\ |
|
117 |
} while (0) |
|
43 | 118 |
#define NMLOG(msg) NM_COMMENT(msg) |
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
119 |
|
40 | 120 |
#else |
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
121 |
|
40 | 122 |
#define NM_COMMENT(msg) |
123 |
#define INFO(msg) |
|
124 |
#define INFO_1(msg,arg1) |
|
125 |
#define INFO_2(msg,arg1,arg2) |
|
126 |
#define INFO_3(msg,arg1,arg2,arg3) |
|
43 | 127 |
#define NMLOG(msg) |
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
128 |
|
44 | 129 |
#endif /* NM_COMMENT_TRACES */ |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
130 |
|
40 | 131 |
/* |
132 |
* The function NM_ERROR() prints its second argument if the first argument |
|
133 |
* is non-zero. The ERROR macros are provided for legacy compatibility. They |
|
134 |
* are deprecated and should not be used. If sprintf() type of formatting is |
|
135 |
* desired, consider using QString::arg() or QTextStream. |
|
136 |
*/ |
|
44 | 137 |
#if NM_ERROR_TRACES |
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
138 |
|
40 | 139 |
inline void NM_ERROR(int err, const QString& msg) |
140 |
{ |
|
141 |
if (err) { |
|
142 |
print_trace("ERROR : " + msg); |
|
143 |
} |
|
144 |
} |
|
145 |
#define ERROR(err,msg) NM_ERROR(err,msg) |
|
146 |
#define ERROR_1(err,msg,arg1)\ |
|
147 |
do {\ |
|
148 |
QString __msg;\ |
|
149 |
__msg.sprintf(msg,arg1);\ |
|
150 |
NM_ERROR(err,__msg);\ |
|
151 |
} while (0) |
|
152 |
#define ERROR_2(err,msg,arg1,arg2)\ |
|
153 |
do {\ |
|
154 |
QString __msg;\ |
|
155 |
__msg.sprintf(msg,arg1,arg2);\ |
|
156 |
NM_ERROR(err,__msg);\ |
|
157 |
} while(0) |
|
158 |
#define ERROR_3(err,msg,arg1,arg2,arg3)\ |
|
159 |
do {\ |
|
160 |
QString __msg;\ |
|
47 | 161 |
__msg.sprintf(msg,arg1,arg2,arg3);\ |
40 | 162 |
NM_ERROR(err,__msg);\ |
163 |
} while(0) |
|
164 |
#define ERROR_GEN(msg) ERROR(KErrGeneral,msg) |
|
165 |
#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
|
166 |
|
40 | 167 |
#else |
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
168 |
|
40 | 169 |
#define NM_ERROR(err,msg) |
170 |
#define ERROR(err,msg) |
|
171 |
#define ERROR_1(err,msg,arg1) |
|
172 |
#define ERROR_2(err,msg,arg1,arg2) |
|
173 |
#define ERROR_3(err,msg,arg1,arg2,arg3) |
|
174 |
#define ERROR_GEN(msg) |
|
175 |
#define ERROR_GEN_1(msg,arg1) |
|
18
578830873419
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
176 |
|
44 | 177 |
#endif /* NM_ERROR_TRACES */ |
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
178 |
|
40 | 179 |
/* |
180 |
* The macro NM_FUNCTION, when used inside a function body, enables tracing |
|
47 | 181 |
* for a function. If used, it should be placed on the first line of the |
182 |
* function body. ENTER and RETURN messages are printed when entering into |
|
44 | 183 |
* and returning from a function, respectively. In case of an exception, |
47 | 184 |
* UNWIND (for stack unwinding) is printed instead of RETURN. The FUNC_LOG |
185 |
* macro is provided for legacy compatibility. It is deprecated and should |
|
186 |
* not be used. |
|
40 | 187 |
*/ |
44 | 188 |
#if NM_FUNCTION_TRACES |
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
189 |
|
40 | 190 |
class __ftracer |
191 |
{ |
|
192 |
public: |
|
193 |
__ftracer(const QString& _fn) |
|
194 |
: fn(_fn) |
|
195 |
{ |
|
196 |
print_trace("ENTER : " + fn); |
|
197 |
} |
|
198 |
~__ftracer() |
|
199 |
{ |
|
200 |
if (std::uncaught_exception()) { |
|
201 |
print_trace("UNWIND : " + fn); |
|
202 |
} else { |
|
203 |
print_trace("RETURN : " + fn); |
|
204 |
} |
|
205 |
} |
|
206 |
private: |
|
207 |
QString fn; |
|
208 |
}; |
|
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
209 |
|
43 | 210 |
#define NM_FUNCTION __ftracer __ft(__PRETTY_FUNCTION__) |
40 | 211 |
#define FUNC_LOG NM_FUNCTION |
212 |
||
213 |
#else |
|
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
214 |
|
40 | 215 |
#define NM_FUNCTION |
216 |
#define FUNC_LOG |
|
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
217 |
|
44 | 218 |
#endif /* NM_FUNCTION_TRACES */ |
0
8466d47a6819
Revision: 200949
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
219 |
|
40 | 220 |
#endif /* EMAILTRACE_H */ |