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