|
1 /* |
|
2 * Copyright (c) 2008-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: Logging macros |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #ifndef GLXLOG_H |
|
22 #define GLXLOG_H |
|
23 |
|
24 // KH 3-August-2007, from now on only log on debug builds because of performance |
|
25 #ifdef _DEBUG |
|
26 #define GLX_LOGGING_ENABLED |
|
27 #endif |
|
28 |
|
29 #ifndef GLX_LOGGING_ENABLED |
|
30 |
|
31 // empty declarations to clean up code |
|
32 #define GLX_LOG_ENTRY_EXIT( s ) |
|
33 #define GLX_LOG_ENTRY_EXIT_LEAVE_L( s ) |
|
34 #define GLX_LOG_INFO( s ) |
|
35 #define GLX_LOG_INFO1( s, i ) |
|
36 #define GLX_LOG_INFO2( s, i, j ) |
|
37 #define GLX_LOG_INFO3( s, i, j, k ) |
|
38 #define GLX_LOG_INFO4( s, i, j, k, l ) |
|
39 #define GLX_LOG_INFO5( s, i, j, k, l, m ) |
|
40 #define GLX_LOG_WARNING( s ) |
|
41 #define GLX_LOG_WARNING1( s, i ) |
|
42 #define GLX_LOG_WARNING2( s, i, j ) |
|
43 #define GLX_LOG_WARNING3( s, i, j, k ) |
|
44 #define GLX_LOG_ERROR( s ) |
|
45 #define GLX_LOG_ERROR1( s, i ) |
|
46 #define GLX_LOG_ERROR2( s, i, j ) |
|
47 #define GLX_LOG_ERROR3( s, i, j, k ) |
|
48 #define GLX_FUNC( s ) |
|
49 #define GLX_FUNCL( s ) |
|
50 #define GLX_DEBUG1( s ) |
|
51 #define GLX_DEBUG2( s, i ) |
|
52 #define GLX_DEBUG3( s, i, j ) |
|
53 #define GLX_DEBUG4( s, i, j, k ) |
|
54 #define GLX_DEBUG5( s, i, j, k, l ) |
|
55 #define GLX_LOG_URI( s, i ) |
|
56 #else |
|
57 |
|
58 // only include headers if logging is enabled |
|
59 #include <e32std.h> |
|
60 #include <e32base.h> |
|
61 #include <glxlogger.h> |
|
62 |
|
63 |
|
64 /** |
|
65 * Helper macro for defining debug string with filename |
|
66 * Note! this is internal so dont use outside this header |
|
67 */ |
|
68 /* #ifdef __arm__ |
|
69 // use the module name instead as its the filename without path |
|
70 #define GLX_DEBUG_STR( cat, str ) __MODULE__ "(%d) : " ##cat " : " ##str |
|
71 #else |
|
72 // put full file paths off for __FILE__ macro to make the log entries shorter |
|
73 #pragma fullpath_file off*/ |
|
74 #define GLX_DEBUG_STR( cat, str ) __FILE__ "(%d) : " ##cat " : " ##str |
|
75 // #endif |
|
76 |
|
77 /** |
|
78 * Helper macro for defining debug string with filename and linenumber |
|
79 * @param category the category string for the log entry |
|
80 * @param string the string for the log entry |
|
81 * Note! this is internal so dont use outside this header |
|
82 */ |
|
83 #define GLX_DEBUG_LINE( category, string ) \ |
|
84 TPtrC8((const TText8*) GLX_DEBUG_STR( category, string ) ), __LINE__ |
|
85 |
|
86 /** |
|
87 * Output to glx logger |
|
88 * Note! this is internal so dont use outside this header |
|
89 */ |
|
90 #define GLX_DEBUG_PRINT GlxLogger::WriteFormat |
|
91 |
|
92 // LOGGING MACROS |
|
93 /** |
|
94 * Logs the entry and exit point of the function |
|
95 * Does not log the filename nor linenumber as inlining does not work |
|
96 * if you want to log the filename and linenumber, |
|
97 * use GLX_LOG_INFO macros instead |
|
98 * Example usage: |
|
99 * GLX_LOG_ENTRY_EXIT( "CFoo::Bar()" ); |
|
100 * @param a string to be added to the log |
|
101 */ |
|
102 #define GLX_LOG_ENTRY_EXIT( s ) TGlxFunctionTrace _tracer( _L8( s ) ) |
|
103 |
|
104 /** |
|
105 * Logs the entry, exit and possible leave point of the function. |
|
106 * Note! cannot be used in a non leaving function or inside a LC function |
|
107 * as this macro uses the cleanup stack |
|
108 * Does not log the filename nor linenumber as inlining does not work |
|
109 * if you want to log the filename and linenumber, |
|
110 * use GLX_LOG_INFO macros instead |
|
111 * Example usage: |
|
112 * GLX_LOG_ENTRY_EXIT_LEAVE_L( "CFoo::Bar()" ); |
|
113 * @param a string to be added to the log |
|
114 * @deprecated use GLX_LOG_ENTRY_EXIT instead as it also detects leave and does not require cleanupstack to work |
|
115 */ |
|
116 #define GLX_LOG_ENTRY_EXIT_LEAVE_L( s ) \ |
|
117 TGlxFunctionTraceWithLeaveDetection _tracer( _L8( s ) ); \ |
|
118 CleanupClosePushL( _tracer ) |
|
119 |
|
120 /** |
|
121 * Logs a single line of information and the filename and linenumber |
|
122 * Example usage: |
|
123 * GLX_LOG_INFO( "CFoo::Bar()" ); |
|
124 * @param s, the string to be inserted to the log, plain compile time string, not a descriptor |
|
125 */ |
|
126 #define GLX_LOG_INFO( s ) \ |
|
127 GLX_DEBUG_PRINT( GLX_DEBUG_LINE( "info", s ) ) |
|
128 |
|
129 /** |
|
130 * Logs a single line of information with one parameter |
|
131 * and the filename and linenumber |
|
132 * NOTE! logging is done in 8 bit strings so you cannot format 16 bit descriptor |
|
133 * values. |
|
134 * For the parameter string, use %d for int, %f for float and %S for address of descriptor |
|
135 * Example usage: |
|
136 * GLX_LOG_INFO1( "CFoo::Bar(%d)", aInt ); |
|
137 * @param s, the string to be inserted to the log, plain compile time string, not a descriptor |
|
138 * @param i, value to be inserted to the string, can be of any type |
|
139 */ |
|
140 #define GLX_LOG_INFO1( s, i ) \ |
|
141 GLX_DEBUG_PRINT( GLX_DEBUG_LINE( "info", s ), i ) |
|
142 |
|
143 /** |
|
144 * Logs a single line of information with two parameters |
|
145 * along with the filename and linenumber |
|
146 * For the parameter string, use %d for int, %f for float and %S for address of descriptor |
|
147 * NOTE! logging is done in 8 bit strings so you cannot format 16 bit descriptor |
|
148 * values. |
|
149 * Example usage: |
|
150 * GLX_LOG_INFO2( "CFoo::Bar(%d,%f)", aInt, aFloat ); |
|
151 * @param s, the string to be inserted to the log, plain compile time string, not a descriptor |
|
152 * @param i, value to be inserted to the string, can be of any type |
|
153 * @param j, value to be inserted to the string, can be of any type |
|
154 */ |
|
155 #define GLX_LOG_INFO2( s, i, j ) \ |
|
156 GLX_DEBUG_PRINT( GLX_DEBUG_LINE( "info", s ), i, j ) |
|
157 |
|
158 /** |
|
159 * Logs a single line of information with three parameters |
|
160 * along with the filename and linenumber |
|
161 * For the parameter string, use %d for int, %f for float and %S for address of descriptor |
|
162 * NOTE! logging is done in 8 bit strings so you cannot format 16 bit descriptor |
|
163 * values. |
|
164 * Example usage: |
|
165 * GLX_LOG_INFO3( "CFoo::Bar(%d,%S,%f)", aInt, &aDesC, aFloat ); |
|
166 * @param s, the string to be inserted to the log, plain compile time string, not a descriptor |
|
167 * @param i, value to be inserted to the string, can be of any type |
|
168 * @param j, value to be inserted to the string, can be of any type |
|
169 * @param k, value to be inserted to the string, can be of any type |
|
170 */ |
|
171 #define GLX_LOG_INFO3( s, i, j, k ) \ |
|
172 GLX_DEBUG_PRINT( GLX_DEBUG_LINE( "info", s ), i, j, k ) |
|
173 |
|
174 /** |
|
175 * Logs a single line of information with four parameters |
|
176 * along with the filename and linenumber |
|
177 * For the parameter string, use %d for int, %f for float and %S for address of descriptor |
|
178 * NOTE! logging is done in 8 bit strings so you cannot format 16 bit descriptor |
|
179 * values. |
|
180 * Example usage: |
|
181 * GLX_LOG_INFO4( "CFoo::Bar(%d,%f,%S,%s)", aInt, aFloat, "string" ); |
|
182 * @param s, the string to be inserted to the log, plain compile time string, not a descriptor |
|
183 * @param i, value to be inserted to the string, can be of any type |
|
184 * @param j, value to be inserted to the string, can be of any type |
|
185 * @param k, value to be inserted to the string, can be of any type |
|
186 * @param l, value to be inserted to the string, can be of any type |
|
187 */ |
|
188 #define GLX_LOG_INFO4( s, i, j, k, l ) \ |
|
189 GLX_DEBUG_PRINT( GLX_DEBUG_LINE( "info", s ), i, j, k, l ) |
|
190 |
|
191 /** |
|
192 * Logs a single line of information with five parameters |
|
193 * along with the filename and linenumber |
|
194 * For the parameter string, use %d for int, %f for float and %S for address of descriptor |
|
195 * NOTE! logging is done in 8 bit strings so you cannot format 16 bit descriptor |
|
196 * values. |
|
197 * Example usage: |
|
198 * GLX_LOG_INFO5( |
|
199 * "CFoo::Bar(%.1f,%.2f,%.3f,%.4f,%.5f)", aFloat1, aFloat2, aFloat3, aFloat4, aFloat5 ); |
|
200 * @param s, the string to be inserted to the log, plain compile time string, not a descriptor |
|
201 * @param i, value to be inserted to the string, can be of any type |
|
202 * @param j, value to be inserted to the string, can be of any type |
|
203 * @param k, value to be inserted to the string, can be of any type |
|
204 * @param l, value to be inserted to the string, can be of any type |
|
205 * @param m, value to be inserted to the string, can be of any type |
|
206 */ |
|
207 #define GLX_LOG_INFO5( s, i, j, k, l, m ) \ |
|
208 GLX_DEBUG_PRINT( GLX_DEBUG_LINE( "info", s ), i, j, k, l, m ) |
|
209 |
|
210 /** |
|
211 * Logs a single line of warning and the filename and linenumber |
|
212 * Example usage: |
|
213 * GLX_LOG_WARNING( "Incorrect state, resetting state" ); |
|
214 * @param s, the string to be inserted to the log, plain compile time string, not a descriptor |
|
215 */ |
|
216 #define GLX_LOG_WARNING( s ) \ |
|
217 GLX_DEBUG_PRINT( GLX_DEBUG_LINE( "warning", s ) ) |
|
218 |
|
219 /** |
|
220 * Logs a single line of warning with one parameter |
|
221 * and the filename and linenumber |
|
222 * For the parameter string, use %d for int, %f for float and %S for address of descriptor |
|
223 * NOTE! logging is done in 8 bit strings so you cannot format 16 bit descriptor |
|
224 * values. |
|
225 * Example usage: |
|
226 * GLX_LOG_WARNING1( "Incorrect parameter %d", aInt ); |
|
227 * @param s, the string to be inserted to the log, plain compile time string, not a descriptor |
|
228 * @param i, value to be inserted to the string, can be of any type |
|
229 */ |
|
230 #define GLX_LOG_WARNING1( s, i ) \ |
|
231 GLX_DEBUG_PRINT( GLX_DEBUG_LINE( "warning", s ), i ) |
|
232 |
|
233 /** |
|
234 * Logs a single line of warning with two parameters |
|
235 * along with the filename and linenumber |
|
236 * For the parameter string, use %d for int, %f for float and %S for address of descriptor |
|
237 * NOTE! logging is done in 8 bit strings so you cannot format 16 bit descriptor |
|
238 * values. |
|
239 * Example usage: |
|
240 * GLX_LOG_WARNING2( "Incorrect parameter %f, defaulting to %f", aInputFloat, KDefaultFloat ); |
|
241 * @param s, the string to be inserted to the log, plain compile time string, not a descriptor |
|
242 * @param i, value to be inserted to the string, can be of any type |
|
243 * @param j, value to be inserted to the string, can be of any type |
|
244 */ |
|
245 #define GLX_LOG_WARNING2( s, i, j ) \ |
|
246 GLX_DEBUG_PRINT( GLX_DEBUG_LINE( "warning", s ), i , j ) |
|
247 |
|
248 /** |
|
249 * Logs a single line of warning with three parameters |
|
250 * along with the filename and linenumber |
|
251 * For the parameter string, use %d for int, %f for float and %S for address of descriptor |
|
252 * NOTE! logging is done in 8 bit strings so you cannot format 16 bit descriptor |
|
253 * values. |
|
254 * Example usage: |
|
255 * GLX_LOG_WARNING3( "Incorrect size (%d,%d), scale is %f", aWidth, aHeight, aScale ); |
|
256 * @param s, the string to be inserted to the log, plain compile time string, not a descriptor |
|
257 * @param i, value to be inserted to the string, can be of any type |
|
258 * @param j, value to be inserted to the string, can be of any type |
|
259 * @param k, value to be inserted to the string, can be of any type |
|
260 */ |
|
261 #define GLX_LOG_WARNING3( s, i, j, k ) \ |
|
262 GLX_DEBUG_PRINT( GLX_DEBUG_LINE( "warning", s ), i, j, k ) |
|
263 |
|
264 /** |
|
265 * Logs a single line of error and the filename and linenumber. |
|
266 * Use this macro to track your asserts and panics so you can see them in the log and |
|
267 * have a trace to come back to later on. |
|
268 * NOTE! logging is done in 8 bit strings so you cannot format 16 bit descriptor |
|
269 * values. |
|
270 * Example usage: |
|
271 * GLX_LOG_ERROR( "Incorrect state, going to panic" ); |
|
272 * @param s, the string to be inserted to the log, plain compile time string, not a descriptor |
|
273 */ |
|
274 #define GLX_LOG_ERROR( s ) GLX_DEBUG_PRINT( GLX_DEBUG_LINE( "error", s ) ) |
|
275 |
|
276 /** |
|
277 * Logs a single line of error with one parameter and the filename and linenumber |
|
278 * Use this macro to track your asserts and panics so you can see them in the log and |
|
279 * have a trace to come back to later on. |
|
280 * For the parameter string, use %d for int, %f for float and %S for address of descriptor |
|
281 * NOTE! logging is done in 8 bit strings so you cannot format 16 bit descriptor |
|
282 * values. |
|
283 * Example usage: |
|
284 * GLX_LOG_ERROR1( "Incorrect parameter %d, panicing", aInt ); |
|
285 * @param s, the string to be inserted to the log, plain compile time string, not a descriptor |
|
286 * @param i, value to be inserted to the string, can be of any type |
|
287 */ |
|
288 #define GLX_LOG_ERROR1( s, i ) \ |
|
289 GLX_DEBUG_PRINT( GLX_DEBUG_LINE( "error", s ), i ) |
|
290 |
|
291 /** |
|
292 * Logs a single line of error with one parameter and the filename and linenumber |
|
293 * Use this macro to track your asserts and panics so you can see them in the log and |
|
294 * have a trace to come back to later on. |
|
295 * For the parameter string, use %d for int, %f for float and %S for address of descriptor |
|
296 * NOTE! logging is done in 8 bit strings so you cannot format 16 bit descriptor |
|
297 * values. |
|
298 * Example usage: |
|
299 * GLX_LOG_ERROR2( "Incorrect size (%d,%d), panicking", aWidth, aHeight ); |
|
300 * @param s, the string to be inserted to the log, plain compile time string, not a descriptor |
|
301 * @param i, value to be inserted to the string, can be of any type |
|
302 * @param j, value to be inserted to the string, can be of any type |
|
303 */ |
|
304 #define GLX_LOG_ERROR2( s, i, j ) \ |
|
305 GLX_DEBUG_PRINT( GLX_DEBUG_LINE( "error", s ), i, j ) |
|
306 |
|
307 /** |
|
308 * Logs a single line of error with one parameter and the filename and linenumber |
|
309 * Use this macro to track your asserts and panics so you can see them in the log and |
|
310 * have a trace to come back to later on. |
|
311 * For the parameter string, use %d for int, %f for float and %S for address of descriptor |
|
312 * NOTE! logging is done in 8 bit strings so you cannot format 16 bit descriptor |
|
313 * values. |
|
314 * Example usage: |
|
315 * GLX_LOG_ERROR3( "Incorrect state %d,%d,%f, panicking", aInt, aInt2, aFloat ); |
|
316 * @param s, the string to be inserted to the log, plain compile time string, not a descriptor |
|
317 * @param i, value to be inserted to the string, can be of any type |
|
318 * @param j, value to be inserted to the string, can be of any type |
|
319 * @param k, value to be inserted to the string, can be of any type |
|
320 */ |
|
321 #define GLX_LOG_ERROR3( s, i, j, k ) \ |
|
322 GLX_DEBUG_PRINT( GLX_DEBUG_LINE( "error", s ), i, j, k ) |
|
323 |
|
324 // Old macros for compatibility |
|
325 ///@deprecated, use GLX_LOG_ENTRY_EXIT instead |
|
326 #define GLX_FUNC( s ) GLX_LOG_ENTRY_EXIT( s ) |
|
327 ///@deprecated, use GLX_LOG_ENTRY_EXIT_LEAVE_L instead |
|
328 #define GLX_FUNCL( s ) GLX_LOG_ENTRY_EXIT_LEAVE_L( s ) |
|
329 ///@deprecated, use GLX_LOG_INFO instead |
|
330 #define GLX_DEBUG1( s ) GLX_LOG_INFO( s ) |
|
331 ///@deprecated, use GLX_LOG_INFO1 instead |
|
332 #define GLX_DEBUG2( s, i ) GLX_LOG_INFO1( s, i ) |
|
333 ///@deprecated, use GLX_LOG_INFO2 instead |
|
334 #define GLX_DEBUG3( s, i, j ) GLX_LOG_INFO2( s, i, j ) |
|
335 ///@deprecated, use GLX_LOG_INFO3 instead |
|
336 #define GLX_DEBUG4( s, i, j, k ) GLX_LOG_INFO3( s, i, j, k ) |
|
337 ///@deprecated, use GLX_LOG_INFO4 instead |
|
338 #define GLX_DEBUG5( s, i, j, k, l ) GLX_LOG_INFO4( s, i, j, k, l ) |
|
339 |
|
340 /** |
|
341 * Logs a single line of information with two parameters |
|
342 * Example usage: |
|
343 * CFoo::SetImageUriL(const TDesC& aFileName) { |
|
344 * GLX_LOG_URI( "CFoo::SetImageUriL(%S)", &aFileName ); } |
|
345 * @param s, the string to be inserted to the log, plain compile time string, not a descriptor |
|
346 * @param i, the string value to be inserted to the string |
|
347 */ |
|
348 #define GLX_LOG_URI( s, i ) RDebug::Print( _L( s ), i ) |
|
349 |
|
350 /** |
|
351 * TRAP instrumentation for Leave |
|
352 */ |
|
353 #undef TRAP_INSTRUMENTATION_LEAVE |
|
354 #define TRAP_INSTRUMENTATION_LEAVE( aResult ) \ |
|
355 GLX_LOG_INFO1( "Leave %d TRAPPED", aResult ) |
|
356 |
|
357 /** |
|
358 * Helper class to track function entry and exit. |
|
359 */ |
|
360 class TGlxFunctionTrace |
|
361 { |
|
362 public: |
|
363 inline TGlxFunctionTrace( TRefByValue< const TDesC8 > aName ) |
|
364 : iStr( aName ) |
|
365 { |
|
366 // not using GLX_DEBUG2 as this function does not inline |
|
367 GLX_DEBUG_PRINT( _L8( "Entry : %S" ), &iStr ); |
|
368 } |
|
369 inline ~TGlxFunctionTrace() |
|
370 { |
|
371 if( std::uncaught_exception() ) |
|
372 { |
|
373 // not using GLX_DEBUG2 as this function does not inline |
|
374 GLX_DEBUG_PRINT( _L8( "Leave: %S" ), &iStr ); |
|
375 } |
|
376 else |
|
377 { |
|
378 // not using GLX_DEBUG2 as this function does not inline |
|
379 GLX_DEBUG_PRINT( _L8( "Exit : %S" ), &iStr ); |
|
380 } |
|
381 } |
|
382 private: |
|
383 TPtrC8 iStr; |
|
384 }; |
|
385 |
|
386 /** |
|
387 * Helper class to track function entry, exit and possible leave. |
|
388 * Never instantiate this class by itself. |
|
389 * Only ever user the macro GLX_FUNCL as this calls CleanupClosePushL |
|
390 * If you don't use the macro the destructor will panic in CleanupStack::Pop( this ) |
|
391 * DO NOT use this in a LC method such as NewLC. |
|
392 * Cleanup stack will be popped in the wrong order causing unwanted behaviour |
|
393 */ |
|
394 class TGlxFunctionTraceWithLeaveDetection |
|
395 { |
|
396 public: |
|
397 inline TGlxFunctionTraceWithLeaveDetection( TRefByValue<const TDesC8> aName ) |
|
398 : iStr( aName ), iLeave( EFalse ) |
|
399 { |
|
400 // not using GLX_DEBUG2 as this function does not inline |
|
401 GLX_DEBUG_PRINT( _L8( "Entry : %S" ), &iStr ); |
|
402 } |
|
403 inline ~TGlxFunctionTraceWithLeaveDetection() |
|
404 { |
|
405 // Did we leave |
|
406 if( iLeave ) |
|
407 { |
|
408 // not using GLX_DEBUG2 as this function does not inline |
|
409 GLX_DEBUG_PRINT( _L8( "Leave : %S" ), &iStr ); |
|
410 } |
|
411 else |
|
412 { |
|
413 // not using GLX_DEBUG2 as this function does not inline |
|
414 GLX_DEBUG_PRINT( _L8( "Exit : %S" ), &iStr ); |
|
415 // Remove this from Cleanup. |
|
416 CleanupStack::Pop( this ); |
|
417 } |
|
418 } |
|
419 void Close() // This is only called if a leave happens. |
|
420 { |
|
421 iLeave = ETrue; |
|
422 } |
|
423 private: |
|
424 TPtrC8 iStr; |
|
425 TBool iLeave; |
|
426 }; |
|
427 |
|
428 #endif |
|
429 |
|
430 #endif // GLXLOG_H |
|
431 |
|
432 // End of File |