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