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