1 /* |
|
2 * ============================================================================== |
|
3 * Name : hglogging.h |
|
4 * Part of : Teleport / Context Services |
|
5 * Description : Defines all available logging macros. |
|
6 * Version : %version: 2 % |
|
7 * |
|
8 * Copyright © 2008 Nokia. All rights reserved. |
|
9 * This material, including documentation and any related |
|
10 * computer programs, is protected by copyright controlled by |
|
11 * Nokia. All rights are reserved. Copying, including |
|
12 * reproducing, storing, adapting or translating, any |
|
13 * or all of this material requires the prior written consent of |
|
14 * Nokia. This material also contains confidential |
|
15 * information which may not be disclosed to others without the |
|
16 * prior written consent of Nokia. |
|
17 * ============================================================================== |
|
18 */ |
|
19 |
|
20 #ifndef HGLOGLOGUTILS_H |
|
21 #define HGLOGLOGUTILS_H |
|
22 |
|
23 /** |
|
24 * @file |
|
25 * |
|
26 * TAKING LOGGING INTO USE: |
|
27 * |
|
28 * This step is needed to do once per component. |
|
29 * |
|
30 * For each component that uses these common logging macros should specify |
|
31 * their own logging configuration file, which includes this file. In that |
|
32 * configuration file, following constants and macros must be defined. |
|
33 * For example: |
|
34 * @code |
|
35 * |
|
36 * _LIT( KHgLogFile, "text_file_for_logging.txt" ); |
|
37 * _LIT( KHgLogPath, "folder_for_text_file" ); |
|
38 * #define _HGLOG_LOG_COMPONENT_ID <some unique number here> |
|
39 * |
|
40 * #include "hglogging.h" |
|
41 * |
|
42 * @/code |
|
43 * |
|
44 * KHgLogFile : This is the name of the file, where all the logs for |
|
45 * this components are being written. |
|
46 * |
|
47 * KHgLogPath : This is the folder name under c:\logs, where the file |
|
48 * is to be stored. For example, if KHgLogPath is "test", |
|
49 * log file is created into folder c:\logs\test. |
|
50 * |
|
51 * _HGLOG_LOG_COMPONENT_ID : Unique number id of the component. This is |
|
52 * for filtering purposes. |
|
53 * |
|
54 * _HGLOG_RDEBUG : When defined tracing instead of file logging. |
|
55 * Default is for file logging. |
|
56 * |
|
57 * -------------------------------------------------------------------------- |
|
58 * |
|
59 * USING LOGGING: |
|
60 * |
|
61 * Basically the use is simple, register function use with HGLOG_CONTEXT, |
|
62 * then log function enter by any HGLOG_IN -macro, then possibly use HGLOG |
|
63 * -macros for function logging and finally HGLOG_OUT -macros for returning |
|
64 * from the function. |
|
65 * |
|
66 * @code |
|
67 * TInt CGood::Example( TInt aSomething ) |
|
68 * { |
|
69 * // Create log context class, which is maintained for lifetime of the |
|
70 * // method. |
|
71 * HGLOG_CONTEXT( Example, HGLOG_LOCAL ); |
|
72 * |
|
73 * // Indicate we are entering the function. |
|
74 * HGLOG_IN1( "aSomething contains value %d", aSomething ); |
|
75 * |
|
76 * // Your buggy code... |
|
77 * |
|
78 * // Before leaving, indicate function execution has ended. |
|
79 * HGLOG_OUT(); |
|
80 * |
|
81 * return 0; |
|
82 * } |
|
83 * @/code |
|
84 */ |
|
85 |
|
86 #include <e32def.h> |
|
87 #include <e32std.h> |
|
88 |
|
89 #include "hglogutils.h" |
|
90 |
|
91 #define HGLOG_API 0 |
|
92 #define HGLOG_LOCAL 1 |
|
93 |
|
94 #define HGLOG_INFO 0 |
|
95 #define HGLOG_WARNING 1 |
|
96 #define HGLOG_ERROR 2 |
|
97 |
|
98 #define HGLOG_ASSERT(_assertion) __HGLOG_ASSERT_DBG(_assertion) |
|
99 #define HGLOG_TRACE_ASSERT(_assertion) __ASSERT_DEBUG((_assertion), User::Invariant() ) |
|
100 |
|
101 #ifdef _DEBUG |
|
102 |
|
103 /***************************************************************************** |
|
104 LOGGING MACROS - LOGGING ON |
|
105 *****************************************************************************/ |
|
106 |
|
107 /** |
|
108 * Context initialization |
|
109 * NOTE: HGLOG_STATIC_CONTEXT is meant for static methods. |
|
110 * |
|
111 * @param _fn Name of the function. |
|
112 * @param _vis Visibility for the client, use values HGLOG_API or HGLOG_LOCAL |
|
113 * @param _thdId For static functions, thread id can be given here. |
|
114 */ |
|
115 #define HGLOG_CONTEXT(_fn, _vis ) _THgLogContext _dc((TText*)L ## #_fn, _HGLOG_LOG_COMPONENT_ID, _vis, (TUint)this, RProcess().SecureId().iId ) |
|
116 #define HGLOG_STATIC_CONTEXT(_fn, _vis, _thdId) _THgLogContext _dc((TText*)L ## #_fn, _HGLOG_LOG_COMPONENT_ID, _vis, _thdId, RProcess().SecureId().iId ) |
|
117 |
|
118 /** |
|
119 * Entering function |
|
120 * |
|
121 * @param string Custom text. Example: HGLOG_IN0( "Yeah!!!" ); |
|
122 * @param p1 - p5 For multiple variables in same string. |
|
123 */ |
|
124 #define HGLOG_IN() do { _CHK_MULTIIN(); _HGLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]>%s "), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn); _MARK_ENTRY(); } while(0) |
|
125 #define HGLOG0_IN(string) do { _CHK_MULTIIN(); _HGLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]>%s " L ## string), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn); _MARK_ENTRY(); } while(0) |
|
126 #define HGLOG1_IN(string, p1) do { _CHK_MULTIIN(); _HGLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]>%s " L ## string), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, p1); _MARK_ENTRY(); } while(0) |
|
127 #define HGLOG2_IN(string, p1, p2) do { _CHK_MULTIIN(); _HGLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]>%s " L ## string), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, p1, p2); _MARK_ENTRY(); } while(0) |
|
128 #define HGLOG3_IN(string, p1, p2, p3) do { _CHK_MULTIIN(); _HGLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]>%s " L ## string), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, p1, p2, p3); _MARK_ENTRY(); } while(0) |
|
129 #define HGLOG4_IN(string, p1, p2, p3, p4) do { _CHK_MULTIIN(); _HGLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]>%s " L ## string), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, p1, p2, p3, p4); _MARK_ENTRY(); } while(0) |
|
130 #define HGLOG5_IN(string, p1, p2, p3, p4, p5) do { _CHK_MULTIIN(); _HGLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]>%s " L ## string), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, p1, p2, p3, p4, p5); _MARK_ENTRY(); } while(0) |
|
131 |
|
132 /** Leaving function */ |
|
133 #define HGLOG_OUT() do { _DOINCHK(); _CHK_MULTIOUT(); _HGLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]<%s "), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn); _MARK_EXIT(); } while(0) |
|
134 #define HGLOG0_OUT(string) do { _DOINCHK(); _CHK_MULTIOUT(); _HGLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]<%s " L ## string), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn); _MARK_EXIT(); } while(0) |
|
135 #define HGLOG1_OUT(string, p1) do { _DOINCHK(); _CHK_MULTIOUT(); _HGLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]<%s " L ## string), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, p1); _MARK_EXIT(); } while(0) |
|
136 #define HGLOG2_OUT(string, p1, p2) do { _DOINCHK(); _CHK_MULTIOUT(); _HGLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]<%s " L ## string), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, p1, p2); _MARK_EXIT(); } while(0) |
|
137 #define HGLOG3_OUT(string, p1, p2, p3) do { _DOINCHK(); _CHK_MULTIOUT(); _HGLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]<%s " L ## string), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, p1, p2, p3); _MARK_EXIT(); } while(0) |
|
138 #define HGLOG4_OUT(string, p1, p2, p3, p4) do { _DOINCHK(); _CHK_MULTIOUT(); _HGLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]<%s " L ## string), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, p1, p2, p3, p4); _MARK_EXIT(); } while(0) |
|
139 #define HGLOG5_OUT(string, p1, p2, p3, p4, p5) do { _DOINCHK(); _CHK_MULTIOUT(); _HGLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]<%s " L ## string), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, p1, p2, p3, p4, p5); _MARK_EXIT(); } while(0) |
|
140 |
|
141 /** Leaving function with return value */ |
|
142 #define HGLOG0_RET(val, fmtstr) do { do { _DOINCHK(); _CHK_MULTIOUT(); _HGLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]<%s " L ## fmtstr), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, val); _MARK_EXIT(); } while(0); return val;} while(0) |
|
143 #define HGLOG1_RET(val, fmtstr, p1) do { do { _DOINCHK(); _CHK_MULTIOUT(); _HGLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]<%s " L ## fmtstr), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, val, p1); _MARK_EXIT(); } while(0); return val;} while(0) |
|
144 #define HGLOG2_RET(val, fmtstr, p1, p2) do { do { _DOINCHK(); _CHK_MULTIOUT(); _HGLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]<%s " L ## fmtstr), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, val, p1, p2); _MARK_EXIT(); } while(0); return val;} while(0) |
|
145 #define HGLOG3_RET(val, fmtstr, p1, p2, p3) do { do { _DOINCHK(); _CHK_MULTIOUT(); _HGLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]<%s " L ## fmtstr), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, val, p1, p2, p3); _MARK_EXIT(); } while(0); return val;} while(0) |
|
146 #define HGLOG4_RET(val, fmtstr, p1, p2, p3, p4) do { do { _DOINCHK(); _CHK_MULTIOUT(); _HGLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]<%s " L ## fmtstr), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, val, p1, p2, p3, p4); _MARK_EXIT(); } while(0); return val;} while(0) |
|
147 #define HGLOG5_RET(val, fmtstr, p1, p2, p3, p4, p5) do { do { _DOINCHK(); _CHK_MULTIOUT(); _HGLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]<%s " L ## fmtstr), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, val, p1, p2, p3, p4, p5); _MARK_EXIT(); } while(0); return val;} while(0) |
|
148 |
|
149 /** |
|
150 * General log lines |
|
151 * |
|
152 * @param level This can be used as internal information |
|
153 * field, such as info, error, warning etc. |
|
154 * @param string Custom string |
|
155 * @param p1 - p5 For multiple variables in same string. |
|
156 */ |
|
157 #define HGLOG0(level, string) do { _DOINCHK(); _HGLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]%s " L ## string), _dc.iVis, level, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn); } while(0) |
|
158 #define HGLOG1(level, string, p1) do { _DOINCHK(); _HGLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]%s " L ## string), _dc.iVis, level, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, p1); } while(0) |
|
159 #define HGLOG2(level, string, p1, p2) do { _DOINCHK(); _HGLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]%s " L ## string), _dc.iVis, level, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, p1, p2); } while(0) |
|
160 #define HGLOG3(level, string, p1, p2, p3) do { _DOINCHK(); _HGLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]%s " L ## string), _dc.iVis, level, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, p1, p2, p3); } while(0) |
|
161 #define HGLOG4(level, string, p1, p2, p3, p4) do { _DOINCHK(); _HGLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]%s " L ## string), _dc.iVis, level, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, p1, p2, p3, p4); } while(0) |
|
162 #define HGLOG5(level, string, p1, p2, p3, p4, p5) do { _DOINCHK(); _HGLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]%s " L ## string), _dc.iVis, level, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, p1, p2, p3, p4, p5); } while(0) |
|
163 |
|
164 /** Error logging */ |
|
165 #define __HGLOG_ASSERT_DBG( _assertion ) do { if( _assertion ) { break; } TFileName file; file.Copy( _L8( __FILE__ ) ); _HGLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]<%s Assert:%S:%d:" L ## #_assertion) , _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, &file, __LINE__ ); User::Invariant(); } while( 0 ) |
|
166 #define __HGLOG_TRACE_ASSERT_DBG(_assertion, _textToPrint, _panicCode) do { if (_assertion) { break; } _HGLOGPRINTER(_IT(L ## "%s%d[%x:%x:%x]<%s ASSERTION FAILED!!! %s file: %s, line: %s"), _dc.iVis, _dc.iCategory, _dc.iId, _dc.iThdId, _dc.iAddr, _dc.iFn, _textToPrint, __FILE__, __LINE__); User::Panic(_L("AssertionFailed"), _panicCode} while(0) |
|
167 #define HGLOG_TRAPHANDLER() _THgLogTrapHandler _traceTrapHandler; _traceTrapHandler.oldHandler = User::SetTrapHandler(&_traceTrapHandler) |
|
168 |
|
169 /***************************************************************************** |
|
170 LOGGING MACROS - NO LOGGING |
|
171 *****************************************************************************/ |
|
172 #else // _DEBUG |
|
173 |
|
174 #define HGLOG_CONTEXT(_fn, _vis ) |
|
175 #define HGLOG_STATIC_CONTEXT(_fn, _vis, _thdId) |
|
176 |
|
177 #define HGLOG_IN() |
|
178 #define HGLOG0_IN(string) |
|
179 #define HGLOG1_IN(string, p1) |
|
180 #define HGLOG2_IN(string, p1, p2) |
|
181 #define HGLOG3_IN(string, p1, p2, p3) |
|
182 #define HGLOG4_IN(string, p1, p2, p3, p4) |
|
183 #define HGLOG5_IN(string, p1, p2, p3, p4, p5) |
|
184 |
|
185 #define HGLOG_OUT() |
|
186 #define HGLOG0_OUT(string) |
|
187 #define HGLOG1_OUT(string, p1) |
|
188 #define HGLOG2_OUT(string, p1, p2) |
|
189 #define HGLOG3_OUT(string, p1, p2, p3) |
|
190 #define HGLOG4_OUT(string, p1, p2, p3, p4) |
|
191 #define HGLOG5_OUT(string, p1, p2, p3, p4, p5) |
|
192 |
|
193 #define HGLOG0_RET(val, fmtstr) return val |
|
194 #define HGLOG1_RET(val, fmtstr, p1) return val |
|
195 #define HGLOG2_RET(val, fmtstr, p1, p2) return val |
|
196 #define HGLOG3_RET(val, fmtstr, p1, p2, p3) return val |
|
197 #define HGLOG4_RET(val, fmtstr, p1, p2, p3, p4) return val |
|
198 #define HGLOG5_RET(val, fmtstr, p1, p2, p3, p4, p5) return val |
|
199 |
|
200 #define HGLOG0(level, string) |
|
201 #define HGLOG1(level, string, p1) |
|
202 #define HGLOG2(level, string, p1, p2) |
|
203 #define HGLOG3(level, string, p1, p2, p3) |
|
204 #define HGLOG4(level, string, p1, p2, p3, p4) |
|
205 #define HGLOG5(level, string, p1, p2, p3, p4, p5) |
|
206 |
|
207 #define BIND_TRACE_TRAPHANDLER() |
|
208 #define TRACE_DECL() TInt _iTraceThreadId |
|
209 #define TRACE_FAST_CREATE(_thdId) _thdId++; |
|
210 #define TRACE_CREATE() |
|
211 |
|
212 #define __HGLOG_ASSERT_DBG(_assertion) |
|
213 #define __TRACE_ASSERT_DBG(_assertion, _message, _panicCode ) |
|
214 |
|
215 #endif // _DEBUG |
|
216 |
|
217 #endif // HGLOGLOGUTILS_H |
|
218 |
|
219 // End of File |
|