|
1 /* |
|
2 * Copyright (c) 2009 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: Debug print definitions |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 /* |
|
20 * |
|
21 * Description: |
|
22 * |
|
23 * Logging tools. Uniforms style to write debug data to |
|
24 * screen using RDebug or to a file with RFileLogger. |
|
25 * |
|
26 * Usage: |
|
27 * 1.Configuring: |
|
28 * |
|
29 * Logging and debug printing is configured with following macros |
|
30 * CHAT_ENABLE_DEBUG_PRINT (defining this enables debug printing) |
|
31 * CHAT_DEBUG_OUTPUT_TO_FILE (now debug printing goes to file) |
|
32 * CHAT_DEBUG_FILENAME "Some.log" (file to store debug log) |
|
33 * |
|
34 * Debug printing can be configured on project level by defining desired |
|
35 * macros in .mmp file like this |
|
36 * //enable file logging |
|
37 * MACRO CHAT_ENABLE_DEBUG_PRINT |
|
38 * MACRO CHAT_DEBUG_OUTPUT_TO_FILE |
|
39 * |
|
40 * You may also automate the debug printing to follow current build |
|
41 * variant like this: |
|
42 * #ifdef _DEBUG |
|
43 * MACRO CHAT_ENABLE_DEBUG_PRINT |
|
44 * #endif // _DEBUG |
|
45 * |
|
46 * The file to write debug log needs to be defined in file level. |
|
47 * (Defining it in mmp file causes errors to build procedure..) |
|
48 * #define CHAT_DEBUG_FILENAME "Example.log" |
|
49 * |
|
50 * When using debug printing to file, flogger.lib needs to be added in |
|
51 * mmp file |
|
52 * LIBRARY flogger.lib |
|
53 * and following directory must be manually done before loggin |
|
54 * (no directory, not logs) Epoc32\Wins\c\logs\IMALERT\ |
|
55 * |
|
56 * |
|
57 * 2.Printing: |
|
58 * |
|
59 * // normal string output: |
|
60 * CHAT_DP( D_CHAT_LIT( "Some text." ) ); >> CHAT: Some text. |
|
61 * CHAT_DP( D_PLAIN_LIT( "Some text." ) ); >> Some text. |
|
62 * CHAT_DP_TXT( "Some text." ); >> CHAT: Some text. |
|
63 * |
|
64 * // string with variables |
|
65 * TInt index( 99 ); |
|
66 * _LIT( KExample, "Example" ); |
|
67 * CHAT_DP( D_CHAT_LIT( "Some text: %d" ), 100 ); >> CHAT: Some text: 100 |
|
68 * CHAT_DP( D_CHAT_LIT( "Some text: %d" ), index ); >> CHAT: Some text: 99 |
|
69 * CHAT_DP( D_CHAT_LIT( "Some text: %S" ), &KExample ); >> CHAT: Some text: Example |
|
70 * |
|
71 * CHAT_DP( D_PLAIN_LIT( "Some text: %d" ), 100 ); >> Some text: 100 |
|
72 * CHAT_DP( D_PLAIN_LIT( "Some text: %d" ), index ); >> Some text: 99 |
|
73 * CHAT_DP( D_PLAIN_LIT( "Some text: %S" ), &KExample ); >> Some text: Example |
|
74 * |
|
75 * |
|
76 * 3.Known issues: |
|
77 * |
|
78 * - If you use macros from .mmp file remember to abld makefile <target> to |
|
79 * change flags from project. |
|
80 * - In statements like CHAT_DP( D_CHAT_LIT("Some text: %S"), &KExample ); |
|
81 * parameters causes still some code to generated in release builds. |
|
82 * Propably it is best to #ifdef all debugprint blocks |
|
83 * with CHAT_ENABLE_DEBUG_PRINT statement. |
|
84 * |
|
85 * ============================================================================ |
|
86 */ |
|
87 |
|
88 |
|
89 #ifndef __CHATDEBUGPRINT_H__ |
|
90 #define __CHATDEBUGPRINT_H__ |
|
91 |
|
92 // Debug logging is enabled, you may enable debug printing in release builds also |
|
93 #ifdef CHAT_ENABLE_DEBUG_PRINT |
|
94 |
|
95 // no include files if no debug printing --> faster compile time |
|
96 // INCLUDES |
|
97 #include <e32std.h> |
|
98 #include <e32svr.h> |
|
99 #include <flogger.h> |
|
100 |
|
101 #ifndef _DEBUG |
|
102 // warn in release build |
|
103 #if defined( __VC32__ ) |
|
104 #pragma message( "Warning: CHAT debug printing is on in release build!" ) // CSI: 68 # Warning for rel builds |
|
105 #else // __GCC32__ |
|
106 #warning "CHAT debug printing is on in release build!" |
|
107 #endif // __VC32__ |
|
108 #endif |
|
109 |
|
110 /** |
|
111 * Depending if the build is UNICODE or not, define the |
|
112 * helper macros that insert CHAT prefix. |
|
113 */ |
|
114 #ifdef _UNICODE |
|
115 #define CHAT_TOKEN_PASTING( s ) L##s |
|
116 #define CHAT_TO_UNICODE( s ) CHAT_TOKEN_PASTING( s ) |
|
117 #define CHAT_DEBUG_STR( m ) CHAT_TO_UNICODE( "CHAT: " ) L##m |
|
118 #else |
|
119 #define CHAT_DEBUG_STR "CHAT: " |
|
120 #endif // _UNICODE |
|
121 |
|
122 |
|
123 /** |
|
124 * Helper macro for defining debug strings with plain debug text. |
|
125 */ |
|
126 #define D_PLAIN_LIT( s ) _L( s ) // CSI: 78 # Debug print |
|
127 |
|
128 |
|
129 /** |
|
130 * Helper macro for defining debug strings with "CHAT:" prefix. |
|
131 */ |
|
132 #define D_CHAT_LIT( s ) TPtrC( ( const TText * ) CHAT_DEBUG_STR( s ) ) |
|
133 |
|
134 |
|
135 |
|
136 #ifdef CHAT_DEBUG_OUTPUT_TO_FILE |
|
137 |
|
138 /** |
|
139 * Method to handle file writing |
|
140 */ |
|
141 inline void CHATDebugWriteFormat( TRefByValue<const TDesC> aFmt,... ) |
|
142 { |
|
143 _LIT( KDir, "IMALERT" ); |
|
144 #ifdef CHAT_DEBUG_FILENAME |
|
145 const static TLitC< sizeof( CHAT_DEBUG_FILENAME ) > KName={ |
|
146 sizeof( CHAT_DEBUG_FILENAME)-1, |
|
147 CHAT_TO_UNICODE( CHAT_DEBUG_FILENAME ) }; |
|
148 #else |
|
149 _LIT( KName, "ChatDebug.log" ); |
|
150 #endif // CHAT_DEBUG_FILENAME |
|
151 |
|
152 // take the ellipsis parameters |
|
153 VA_LIST args; |
|
154 VA_START( args,aFmt ); |
|
155 RFileLogger::WriteFormat( KDir, KName, EFileLoggingModeAppend, |
|
156 aFmt, args ); |
|
157 VA_END( args ); |
|
158 } |
|
159 |
|
160 /** |
|
161 * Actual debug printters. |
|
162 * Output to log file. |
|
163 */ |
|
164 #define CHAT_DP CHATDebugWriteFormat |
|
165 #define CHAT_DP_TXT( s ) CHATDebugWriteFormat( D_CHAT_LIT( s ) ) |
|
166 |
|
167 |
|
168 |
|
169 #else |
|
170 /** |
|
171 * Actual debug printters. |
|
172 * Output to debugger output. |
|
173 */ |
|
174 #define CHAT_DP RDebug::Print |
|
175 #define CHAT_DP_TXT( s ) RDebug::Print( D_CHAT_LIT( s ) ) |
|
176 #endif |
|
177 |
|
178 |
|
179 #else //CHAT_ENABLE_DEBUG_PRINT |
|
180 |
|
181 /** |
|
182 * |
|
183 * Empty implementations for non-debug printing build versions. |
|
184 * |
|
185 */ |
|
186 |
|
187 /** |
|
188 * Dummy struct for checking that all CHAT_DP's define string |
|
189 * literals using space-saving D_PLAIN_LIT or D_CHAT_LIT. |
|
190 */ |
|
191 struct TCHATEmptyDebugString { }; |
|
192 |
|
193 /** |
|
194 * Macro for defining debug-only literal strings (empty release version) |
|
195 */ |
|
196 #define D_PLAIN_LIT( s ) TCHATEmptyDebugString() |
|
197 |
|
198 /** |
|
199 * Macro for defining debug-only literal strings (empty release version) |
|
200 */ |
|
201 #define D_CHAT_LIT( s ) TCHATEmptyDebugString() |
|
202 |
|
203 /** |
|
204 * Macro for empty debug print function |
|
205 */ |
|
206 #define CHAT_DP_TXT( s ) CHAT_DP( D_CHAT_LIT( s ) ) |
|
207 |
|
208 |
|
209 /// Empty debug print function for release builds. |
|
210 inline void CHAT_DP(TCHATEmptyDebugString) |
|
211 { |
|
212 } |
|
213 |
|
214 template< class T1 > |
|
215 inline void CHAT_DP( TCHATEmptyDebugString, T1 ) |
|
216 { |
|
217 } |
|
218 |
|
219 template< class T1, class T2 > |
|
220 inline void CHAT_DP( TCHATEmptyDebugString, T1, T2 ) |
|
221 { |
|
222 } |
|
223 |
|
224 template< class T1, class T2, class T3 > |
|
225 inline void CHAT_DP( TCHATEmptyDebugString, T1, T2, T3 ) |
|
226 { |
|
227 } |
|
228 |
|
229 template< class T1, class T2, class T3, class T4 > |
|
230 inline void CHAT_DP( TCHATEmptyDebugString, T1, T2, T3, T4 ) |
|
231 { |
|
232 } |
|
233 |
|
234 template< class T1, class T2, class T3, class T4, class T5 > |
|
235 inline void CHAT_DP( TCHATEmptyDebugString, T1, T2, T3, T4, T5 ) |
|
236 { |
|
237 } |
|
238 |
|
239 template< class T1, class T2, class T3, class T4, class T5, class T6 > |
|
240 inline void CHAT_DP( TCHATEmptyDebugString, T1, T2, T3, T4, T5, T6 ) |
|
241 { |
|
242 } |
|
243 |
|
244 template< class T1, class T2, class T3, class T4, class T5, class T6, |
|
245 class T7 > |
|
246 inline void CHAT_DP( TCHATEmptyDebugString, T1, T2, T3, T4, T5, T6, T7 ) |
|
247 { |
|
248 } |
|
249 |
|
250 template< class T1, class T2, class T3, class T4, class T5, class T6, |
|
251 class T7, class T8 > |
|
252 inline void CHAT_DP( TCHATEmptyDebugString, T1, T2, T3, T4, T5, T6, T7, T8 ) |
|
253 { |
|
254 } |
|
255 |
|
256 template< class T1, class T2, class T3, class T4, class T5, class T6, |
|
257 class T7, class T8, class T9 > |
|
258 inline void CHAT_DP( TCHATEmptyDebugString, T1, T2, T3, T4, T5, T6, T7, T8, |
|
259 T9 ) |
|
260 { |
|
261 } |
|
262 |
|
263 template< class T1, class T2, class T3, class T4, class T5, class T6, |
|
264 class T7, class T8, class T9, class T10 > |
|
265 inline void CHAT_DP( TCHATEmptyDebugString, T1, T2, T3, T4, T5, T6, T7, T8, |
|
266 T9, T10 ) |
|
267 { |
|
268 } |
|
269 |
|
270 template< class T1, class T2, class T3, class T4, class T5, class T6, |
|
271 class T7, class T8, class T9, class T10, class T11 > |
|
272 inline void CHAT_DP( TCHATEmptyDebugString, T1, T2, T3, T4, T5, T6, T7, T8, |
|
273 T9, T10, T11 ) |
|
274 { |
|
275 } |
|
276 |
|
277 #endif // CHAT_ENABLE_DEBUG_PRINT |
|
278 |
|
279 /* Some general wrappers to CHAT_DP for convenience. |
|
280 * |
|
281 * Since these just wrap CHAT_DP, they work transparently: the macros write |
|
282 * stuff to debug output or to a file, whichever you are using, |
|
283 * you don't have to care. |
|
284 * |
|
285 * Since CHAT_DP is either defined or empty inline, these won't |
|
286 * matter in either build (no, there is no noticeable penalty in compile time) |
|
287 * |
|
288 * There are three types of wrappers, output format is |
|
289 * |
|
290 * "filename:linenumber method - enter" when entering function |
|
291 * "filename:linenumber method - message" when inside function |
|
292 * "filename:linenumber method - done" when exiting function |
|
293 * |
|
294 * Example: |
|
295 * TInt CSomeClass::SomeMethod() |
|
296 * { |
|
297 * CHAT_DP_FUNC_ENTER( "SomeMethod" ); |
|
298 * |
|
299 * TInt i = 41; |
|
300 * |
|
301 * CHAT_DP_FUNC_DP( "SomeMethod", "Doing intensive calculations" ); |
|
302 * |
|
303 * i++; |
|
304 * |
|
305 * CHAT_DP_FUNC_DONE( "SomeMethod" ); |
|
306 * } |
|
307 * |
|
308 * You have to provide the method name yourself since the __FUNCTION__ |
|
309 * preprocessor macro is not understood. |
|
310 */ |
|
311 |
|
312 #include "imalertdebugmacros.h" // WFILE etc. |
|
313 |
|
314 // when entering a function |
|
315 #define CHAT_DP_FUNC_ENTER( method ) \ |
|
316 CHAT_DP( D_CHAT_LIT("%s:%d %s - enter" ), __WFILE__, __LINE__, L ## method ); |
|
317 |
|
318 // debug print |
|
319 #define CHAT_DP_FUNC_DP( method,msg ) \ |
|
320 CHAT_DP( D_CHAT_LIT( "%s:%d %s - %s" ), __WFILE__, __LINE__, L ## method, L ## msg ); |
|
321 |
|
322 // when exiting a function |
|
323 #define CHAT_DP_FUNC_DONE(method) \ |
|
324 CHAT_DP( D_CHAT_LIT( "%s:%d %s - done" ), __WFILE__, __LINE__, L ## method ); |
|
325 |
|
326 #endif // __CHATDEBUGPRINT_H__ |
|
327 |
|
328 |
|
329 // End of File |