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