|
1 /* |
|
2 * Copyright (c) 2004, 2006 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef __LOGFILE_H__ |
|
20 #define __LOGFILE_H__ |
|
21 |
|
22 // INCLUDES |
|
23 #include <eikapp.h> |
|
24 #include <charconv.h> |
|
25 |
|
26 // CONSTANTS |
|
27 _LIT8(KCrLf8, "\r\n"); |
|
28 _LIT(KCrLf, "\r\n"); |
|
29 |
|
30 static const TInt KAsciiStart = 0x20; |
|
31 static const TInt KAsciiEnd = 0x7f; |
|
32 static const TInt KHexCharLeft = '<'; |
|
33 static const TInt KHexCharRight = '>'; |
|
34 static const TInt KNumberOfDecimalPlaces = 3; |
|
35 |
|
36 // FORWARD DECLARATIONS |
|
37 |
|
38 // Link with the following libraries: EFSRV.LIB HAL.LIB CHARCONV.LIB |
|
39 class CCnvCharacterSetConverter; |
|
40 |
|
41 // CLASS DECLARATIONS |
|
42 /** |
|
43 * CLogFile |
|
44 * Class to generate a text file containing logging information |
|
45 */ |
|
46 class CLogFile : public CBase |
|
47 { |
|
48 public: |
|
49 /** |
|
50 * NewL |
|
51 * Create a CLogFile object |
|
52 * @param aFileName the name of the file to create |
|
53 * @param aInitialiseLog if true, and the log file |
|
54 * already exists, previous contents will be deleted. |
|
55 * If false, append to any existing contents |
|
56 * @return a pointer to the created instance of CLogFile |
|
57 */ |
|
58 static CLogFile* NewL( const TDesC& aFileName, |
|
59 TBool aInitialiseLog ); |
|
60 |
|
61 /** |
|
62 * NewLC |
|
63 * Create a CLogFile object |
|
64 * @param aFileName the name of the file to create |
|
65 * @param aInitialiseLog if true, and the log file |
|
66 * already exists, previous contents will be deleted. |
|
67 * If false, append to any existing contents. |
|
68 * @return a pointer to the created instance of CLogFile |
|
69 */ |
|
70 static CLogFile* NewLC( const TDesC& aFileName, |
|
71 TBool aInitialiseLog ); |
|
72 |
|
73 /** |
|
74 * ~CLogFile |
|
75 * Destroy the object and release all memory objects |
|
76 */ |
|
77 virtual ~CLogFile(); |
|
78 |
|
79 /** |
|
80 * Log |
|
81 * Append the byte to the log file (if not a printable char, it |
|
82 * will be logged as ascii-hex). |
|
83 * @param aByte the byte to log |
|
84 */ |
|
85 void Log( TUint8 aByte ); |
|
86 |
|
87 /** |
|
88 * Log |
|
89 * Append the integer to the log file (logged as ascii-hex) |
|
90 * @param aNumber the integer to log |
|
91 */ |
|
92 void Log( TUint aNumber ); |
|
93 |
|
94 /** |
|
95 * Log |
|
96 * Append text to the log file |
|
97 * @param aText the text to log |
|
98 */ |
|
99 void Log( const TDesC8& aText ); |
|
100 |
|
101 /** |
|
102 * Log |
|
103 * Append text to the log file |
|
104 * @param aText the text to log |
|
105 */ |
|
106 void Log( const TDesC& aText ); |
|
107 |
|
108 /** |
|
109 *LogTime |
|
110 * Append a timestamp to the log file. |
|
111 * Timestamps are in seconds with three decimal places |
|
112 * (but resolution is limited to system timer tick period). |
|
113 */ |
|
114 void LogTime(); |
|
115 |
|
116 /** |
|
117 * LogBytes |
|
118 * Append the bytes to the log file (non-printable bytes will be |
|
119 * logged as ascii-hex). |
|
120 * @param aBuffer the bytes to log |
|
121 */ |
|
122 void LogBytes( const TDesC8& aBuffer ); |
|
123 |
|
124 /** |
|
125 * LogNewline |
|
126 * Start a newline in the log file |
|
127 */ |
|
128 void LogNewline(); |
|
129 |
|
130 /** |
|
131 * SetAutoFlush |
|
132 * Turn AutoFlush on or off. AutoFlush will automatically flush |
|
133 * the log file after each write. |
|
134 * @param aOn if true turns AutoFlush on |
|
135 */ |
|
136 void SetAutoFlush( TBool aOn ); |
|
137 |
|
138 /** |
|
139 * SetAutoTimeStamp |
|
140 * Turn AutoTimeStamp on or off. AutoTimeStamp will add |
|
141 * a timestamp to the start of each new line in the log. |
|
142 * @param aOn if true turn AutoTimeStamp on |
|
143 */ |
|
144 void SetAutoTimeStamp( TBool aOn ); |
|
145 |
|
146 /** |
|
147 * SetAutoNewline |
|
148 * Turn AutoNewline on or off. AutoNewline |
|
149 * starts a new line after each log operation. |
|
150 * @param aOn if true turn AutoNewline on |
|
151 */ |
|
152 void SetAutoNewline( TBool aOn ); |
|
153 |
|
154 /** |
|
155 * StaticLogL |
|
156 * Static option to append text to the log file |
|
157 * @param aFileName the file to append to |
|
158 * @param aText the text to append |
|
159 */ |
|
160 static void StaticLogL( const TDesC& aFileName, |
|
161 const TDesC8& aText ); |
|
162 |
|
163 /** |
|
164 * StaticLogL |
|
165 * Static option to append text to the log file |
|
166 * @param aFileName the file to append to |
|
167 * @param aText the text to append |
|
168 */ |
|
169 static void StaticLogL( const TDesC& aFileName, |
|
170 const TDesC& aText ); |
|
171 |
|
172 private: |
|
173 |
|
174 /** |
|
175 * CLogFile |
|
176 * Perform the first phase of two phase construction |
|
177 */ |
|
178 CLogFile(); |
|
179 |
|
180 /** |
|
181 * ConstructL |
|
182 * Perform the second phase construction of a CLogFile object |
|
183 * @param aFileName the file to open |
|
184 * @param aInitialiseLog if true, and the log file already exists, |
|
185 * previous contents will be deleted. If false, |
|
186 * append to any existing contents |
|
187 */ |
|
188 void ConstructL( const TDesC& aFileName, TBool aInitialiseLog ); |
|
189 |
|
190 /** |
|
191 * LogTimeInternal |
|
192 * Internal function to log time |
|
193 */ |
|
194 void LogTimeInternal(); |
|
195 |
|
196 /** |
|
197 * LogTextInternal |
|
198 * Internal function to log text |
|
199 * @param aText the text to log |
|
200 */ |
|
201 void LogTextInternal( const TDesC8& aText ); |
|
202 |
|
203 /** |
|
204 * LogByteInternal |
|
205 * internal function to log a byte |
|
206 * @param aByte the byte to log |
|
207 */ |
|
208 void LogByteInternal( TUint8 aByte ); |
|
209 |
|
210 /** |
|
211 * LogIntInternal |
|
212 * Internal function to log an integer |
|
213 * @param aNumber the integer to log |
|
214 */ |
|
215 void LogIntInternal( TUint aNumber ); |
|
216 |
|
217 /** |
|
218 * StartWrite |
|
219 * Perform any initial operation before the main log operation |
|
220 */ |
|
221 void StartWrite(); |
|
222 |
|
223 /** |
|
224 * EndWrite |
|
225 * Perform any tidying up operations after the main log operation |
|
226 */ |
|
227 void EndWrite(); |
|
228 |
|
229 /** |
|
230 * Write |
|
231 * Do the actual writing, and associated error checking |
|
232 * @param aText the text to write |
|
233 */ |
|
234 void Write( const TDesC8& aText ); |
|
235 |
|
236 private: |
|
237 |
|
238 /** |
|
239 * iLogFile handle to the log file |
|
240 */ |
|
241 RFile iLogFile; |
|
242 |
|
243 /** |
|
244 * iSession file server session |
|
245 */ |
|
246 RFs iSession; |
|
247 |
|
248 /** |
|
249 * iLogMillisecsPerTick number of millisecs per system timer tick |
|
250 */ |
|
251 TInt iLogMillisecsPerTick; |
|
252 |
|
253 /** |
|
254 * iAutoFlush flag - AutoFlush on |
|
255 */ |
|
256 TBool iAutoFlush; |
|
257 |
|
258 /** |
|
259 * iAutoTimestamp flag - AutoTimeStamp on |
|
260 */ |
|
261 TBool iAutoTimestamp; |
|
262 |
|
263 /** |
|
264 * iAutoNewline flag - AutoNewline on |
|
265 */ |
|
266 TBool iAutoNewline; |
|
267 |
|
268 /** |
|
269 * iCheckNestDepth internal to check StartWrite and EndWrite have |
|
270 * been called correctly |
|
271 */ |
|
272 TInt iCheckNestDepth; |
|
273 |
|
274 /** |
|
275 * iCharacterConverter converts between unicode and |
|
276 * non-unicode characters |
|
277 */ |
|
278 CCnvCharacterSetConverter* iCharacterConverter; |
|
279 |
|
280 /** |
|
281 * iConverterAvailability flag indicating if conversion |
|
282 * is able to occur |
|
283 */ |
|
284 CCnvCharacterSetConverter::TAvailability iConverterAvailability; |
|
285 }; |
|
286 |
|
287 #endif // __LOGFILE_H__ |
|
288 |
|
289 // End of File |