|
1 /* |
|
2 * Copyright (c) 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: This module contains implementation of CStifLogger |
|
15 * class member functions. |
|
16 * |
|
17 */ |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32std.h> |
|
21 #include "StifLogger.h" |
|
22 #include "STFLogger.h" |
|
23 #include "STFLoggerOverFlow.h" |
|
24 #include "SettingServerClient.h" |
|
25 |
|
26 CStifLogger::CStifLogger() : |
|
27 iLogger(NULL) |
|
28 { |
|
29 } |
|
30 |
|
31 void CStifLogger::ConstructL(const TDesC& aTestPath, const TDesC& aTestFile, |
|
32 TLoggerType aLoggerType, TOutput aOutput, TBool aOverWrite, |
|
33 TBool aWithTimeStamp, TBool aWithLineBreak, TBool aWithEventRanking, |
|
34 TBool aThreadIdToLogFile, TBool aCreateLogDir, |
|
35 TInt aStaticBufferSize, TBool aUnicode) |
|
36 { |
|
37 TInt ret; |
|
38 if(!iLogger) |
|
39 { |
|
40 iLogger = new (ELeave) RSTFLogger(); |
|
41 ret = iLogger->Connect(); |
|
42 if (ret) |
|
43 { |
|
44 User::Leave(ret); |
|
45 } |
|
46 } |
|
47 ret = iLogger->CreateL(aTestPath, aTestFile, aLoggerType, aOutput, |
|
48 aOverWrite, aWithTimeStamp, aWithLineBreak, aWithEventRanking, |
|
49 aThreadIdToLogFile, aCreateLogDir, aStaticBufferSize, aUnicode); |
|
50 if (ret) |
|
51 { |
|
52 User::Leave(ret); |
|
53 } |
|
54 } |
|
55 |
|
56 void CStifLogger::ConstructL(const TDesC& aTestPath, const TDesC& aTestFile, |
|
57 TLoggerSettings& aLoggerSettings) |
|
58 { |
|
59 |
|
60 TInt ret; |
|
61 if(!iLogger) |
|
62 { |
|
63 iLogger = new (ELeave) RSTFLogger(); |
|
64 ret = iLogger->Connect(); |
|
65 if (ret) |
|
66 { |
|
67 User::Leave(ret); |
|
68 } |
|
69 } |
|
70 ret = iLogger->CreateL(aTestPath, aTestFile, aLoggerSettings); |
|
71 if (ret) |
|
72 { |
|
73 User::Leave(ret); |
|
74 } |
|
75 } |
|
76 |
|
77 /* |
|
78 ------------------------------------------------------------------------------- |
|
79 |
|
80 Class: CStifLogger |
|
81 |
|
82 Method: NewL |
|
83 |
|
84 Description: Two-phased constructor. |
|
85 |
|
86 Parameters: const TDesC& aTestPath: in: Path to logged information |
|
87 const TDesC& aTestFile: in: Log name for information |
|
88 TLoggerType aLoggerType: in: Log file type(txt, html, |
|
89 data) |
|
90 TOutput aOutput: in: Output source(File) |
|
91 TBool aOverWrite: in: Indicator to file overwrite |
|
92 TBool aWithTimeStamp: in: Indicator to time stamp |
|
93 TBool aWithLineBreak: in: Indicator to line break |
|
94 TBool aWithEventRanking: in: Indicator to event ranking |
|
95 TBool aThreadIdToLogFile: in: Indicator to thread id adding to |
|
96 end of the log file |
|
97 TBool aCreateLogDir: in: Indicator to directory creation |
|
98 TInt aStaticBufferSize |
|
99 TBool aUnicode: in: Indicator if file has to be in unicode format |
|
100 |
|
101 Return Values: CStifLogger* logger: pointer to CStifLogger object |
|
102 |
|
103 Errors/Exceptions: Leaves if aTestPath or aTestFile length is over KMaxName |
|
104 Leaves if called serv.Connect() method fails |
|
105 Leaves if called CHtmlLogger::NewL method fails |
|
106 Leaves if called CDataLogger::NewL method fails |
|
107 Leaves if called CTxtLogger::NewL method fails |
|
108 |
|
109 Status: Proposal |
|
110 |
|
111 ------------------------------------------------------------------------------- |
|
112 */ |
|
113 EXPORT_C CStifLogger* CStifLogger::NewL(const TDesC& aTestPath, |
|
114 const TDesC& aTestFile, TLoggerType aLoggerType, TOutput aOutput, |
|
115 TBool aOverWrite, TBool aWithTimeStamp, TBool aWithLineBreak, |
|
116 TBool aWithEventRanking, TBool aThreadIdToLogFile, |
|
117 TBool aCreateLogDir, TInt aStaticBufferSize, TBool aUnicode) |
|
118 { |
|
119 if( KMaxName < aTestPath.Length() || KMaxName < aTestFile.Length() ) |
|
120 { |
|
121 User::Leave( KErrArgument ); |
|
122 } |
|
123 |
|
124 CStifLogger* self = new (ELeave) CStifLogger(); |
|
125 CleanupStack::PushL(self); |
|
126 |
|
127 self->ConstructL(aTestPath, aTestFile, aLoggerType, aOutput, aOverWrite, |
|
128 aWithTimeStamp, aWithLineBreak, aWithEventRanking, |
|
129 aThreadIdToLogFile, aCreateLogDir, aStaticBufferSize, aUnicode); |
|
130 CleanupStack::Pop(self); |
|
131 return self; |
|
132 } |
|
133 |
|
134 /* |
|
135 ------------------------------------------------------------------------------- |
|
136 |
|
137 Class: CStifLogger |
|
138 |
|
139 Method: NewL |
|
140 |
|
141 Description: Two-phased constructor. |
|
142 |
|
143 TestEngine's and TestServer's are friend. For TestEngine's and |
|
144 TestServer's StifLogger creation. |
|
145 |
|
146 Parameters: const TDesC& aTestPath: in: Path to logged information |
|
147 const TDesC& aTestFile: in: Log name for information |
|
148 TLoggerSettings& aLoggerSettings: in: Struct for StifLogger |
|
149 settigs |
|
150 |
|
151 Return Values: CStifLogger* logger: pointer to CStifLogger object |
|
152 |
|
153 Errors/Exceptions: Leaves if called CHtmlLogger::NewL method fails |
|
154 Leaves if called CDataLogger::NewL method fails |
|
155 Leaves if called CTxtLogger::NewL method fails |
|
156 |
|
157 Status: Proposal |
|
158 |
|
159 ------------------------------------------------------------------------------- |
|
160 */ |
|
161 EXPORT_C CStifLogger* CStifLogger::NewL(const TDesC& aTestPath, |
|
162 const TDesC& aTestFile, TLoggerSettings& aLoggerSettings) |
|
163 { |
|
164 CStifLogger* self = new (ELeave) CStifLogger(); |
|
165 CleanupStack::PushL(self); |
|
166 self->ConstructL(aTestPath, aTestFile, aLoggerSettings); |
|
167 CleanupStack::Pop(self); |
|
168 return self; |
|
169 |
|
170 } |
|
171 |
|
172 CStifLogger::~CStifLogger() |
|
173 { |
|
174 if (iLogger) |
|
175 { |
|
176 iLogger->Close(); |
|
177 delete iLogger; |
|
178 } |
|
179 } |
|
180 |
|
181 void CStifLogger::OverwriteLoggerSettings( |
|
182 TLoggerSettings& /*aLoggerSettings*/, TName& /*aTestPath*/, |
|
183 TName& /*aTestFile*/, TLoggerType& /*aLoggerType*/, |
|
184 TOutput& /*aOutput*/, TBool& /*aOverWrite*/, |
|
185 TBool& /*aWithTimeStamp*/, TBool& /*aWithLineBreak*/, |
|
186 TBool& /*aWithEventRanking*/, TBool& /*aThreadIdToLogFile*/, |
|
187 TBool& /*aCreateLogDir*/, TBool& /*aUnicode*/) |
|
188 { |
|
189 //Keep nothing to do. |
|
190 } |
|
191 |
|
192 EXPORT_C TInt CStifLogger::Log(const TDesC& aLogInfo) |
|
193 { |
|
194 // No text style info |
|
195 return iLogger->Log(ENoStyle, aLogInfo); |
|
196 |
|
197 } |
|
198 |
|
199 EXPORT_C TInt CStifLogger::Log(const TDesC8& aLogInfo) |
|
200 { |
|
201 // No text style info |
|
202 return iLogger->Log(ENoStyle, aLogInfo); |
|
203 |
|
204 } |
|
205 |
|
206 EXPORT_C TInt CStifLogger::Log(TInt aStyle, const TDesC& aLogInfo) |
|
207 { |
|
208 return iLogger->Log(aStyle, aLogInfo); |
|
209 |
|
210 } |
|
211 |
|
212 EXPORT_C TInt CStifLogger::Log(TInt aStyle, const TDesC8& aLogInfo) |
|
213 { |
|
214 return iLogger->Log(aStyle, aLogInfo); |
|
215 |
|
216 } |
|
217 |
|
218 EXPORT_C TInt CStifLogger::Log(TRefByValue<const TDesC> aLogInfo, ...) |
|
219 { |
|
220 VA_LIST list; |
|
221 VA_START( list, aLogInfo ); |
|
222 TLogInfo logInfo; |
|
223 |
|
224 TDesSTFLoggerOverflowHandler overFlowHandler(iLogger, 1); |
|
225 |
|
226 // Parse parameters |
|
227 logInfo.AppendFormatList(aLogInfo, list, &overFlowHandler); |
|
228 |
|
229 // No text style info |
|
230 return iLogger->Log(ENoStyle, logInfo); |
|
231 |
|
232 } |
|
233 |
|
234 /* |
|
235 ------------------------------------------------------------------------------- |
|
236 |
|
237 Class: CStifLogger |
|
238 |
|
239 Method: Log |
|
240 |
|
241 Description: Log a 8 bit information. |
|
242 |
|
243 This log method accepts several parameters. |
|
244 |
|
245 Parameters: TRefByValue<const TDesC8> aLogInfo: in: A templated class which |
|
246 encapsulates a reference to an object within a wrapper |
|
247 |
|
248 Return Values: TInt: Symbian error code. |
|
249 |
|
250 Errors/Exceptions: TDes8LoggerOverflowHandler called if logged information is |
|
251 over KMaxLogData |
|
252 |
|
253 Status: Approved |
|
254 |
|
255 ------------------------------------------------------------------------------- |
|
256 */ |
|
257 EXPORT_C TInt CStifLogger::Log(TRefByValue<const TDesC8> aLogInfo, ...) |
|
258 { |
|
259 VA_LIST list; |
|
260 VA_START( list, aLogInfo ); |
|
261 TLogInfo8 logInfo; |
|
262 // Create overflow handler. If the log information size is over the |
|
263 // KMaxLogData rest of the information will cut. |
|
264 TDes8STFLoggerOverflowHandler overFlowHandler(iLogger, 1); |
|
265 // Parse parameters |
|
266 logInfo.AppendFormatList(aLogInfo, list, &overFlowHandler); |
|
267 // No text style info |
|
268 return iLogger->Log(ENoStyle, logInfo); |
|
269 } |
|
270 |
|
271 /* |
|
272 ------------------------------------------------------------------------------- |
|
273 |
|
274 Class: CStifLogger |
|
275 |
|
276 Method: Log |
|
277 |
|
278 Description: Log a 16 bit information. |
|
279 |
|
280 This log method accepts several parameters. There is also parameter to |
|
281 styling text information e.g. text color. |
|
282 |
|
283 Parameters: TInt aStyle: in: Logged text forming parameter |
|
284 TRefByValue<const TDesC> aLogInfo: in: A templated class |
|
285 which encapsulates a reference to an object |
|
286 within a wrapper |
|
287 |
|
288 Return Values: TInt: Symbian error code. |
|
289 |
|
290 Errors/Exceptions: TDesOverflowHandler called if logged information is |
|
291 over KMaxLogData |
|
292 |
|
293 Status: Approved |
|
294 |
|
295 ------------------------------------------------------------------------------- |
|
296 */ |
|
297 EXPORT_C TInt CStifLogger::Log(TInt aStyle, |
|
298 TRefByValue<const TDesC> aLogInfo, ...) |
|
299 { |
|
300 VA_LIST list; |
|
301 VA_START( list, aLogInfo ); |
|
302 TLogInfo logInfo; |
|
303 |
|
304 // Create overflow handler. If the log information size is over the |
|
305 // KMaxLogData rest of the information will cut. |
|
306 TDesSTFLoggerOverflowHandler overFlowHandler(iLogger, 2); |
|
307 |
|
308 // Parse parameters |
|
309 logInfo.AppendFormatList(aLogInfo, list, &overFlowHandler); |
|
310 |
|
311 return iLogger->Log(aStyle, logInfo); |
|
312 |
|
313 } |
|
314 |
|
315 /* |
|
316 ------------------------------------------------------------------------------- |
|
317 |
|
318 Class: CStifLogger |
|
319 |
|
320 Method: Log |
|
321 |
|
322 Description: Log a 8 bit information. |
|
323 |
|
324 This log method accepts several parameters. There is also parameter to |
|
325 styling text information e.g. text color. |
|
326 |
|
327 Parameters: TInt aStyle: in: Logged text forming parameter |
|
328 TRefByValue<const TDesC8> aLogInfo: in: A templated class |
|
329 which encapsulates a reference to an object |
|
330 within a wrapper |
|
331 |
|
332 Return Values: TInt: Symbian error code. |
|
333 |
|
334 Errors/Exceptions: TDes8LoggerOverflowHandler called if logged information is |
|
335 over KMaxLogData |
|
336 |
|
337 Status: Approved |
|
338 |
|
339 ------------------------------------------------------------------------------- |
|
340 */ |
|
341 EXPORT_C TInt CStifLogger::Log(TInt aStyle, |
|
342 TRefByValue<const TDesC8> aLogInfo, ...) |
|
343 { |
|
344 VA_LIST list; |
|
345 VA_START( list, aLogInfo ); |
|
346 TLogInfo8 logInfo; |
|
347 |
|
348 // Create overflow handler. If the log information size is over the |
|
349 // KMaxLogData rest of the information will cut. |
|
350 TDes8STFLoggerOverflowHandler overFlowHandler(iLogger, 2); |
|
351 |
|
352 // Parse parameters |
|
353 logInfo.AppendFormatList(aLogInfo, list, &overFlowHandler); |
|
354 |
|
355 return iLogger->Log(aStyle, logInfo); |
|
356 |
|
357 } |
|
358 |
|
359 /* |
|
360 ------------------------------------------------------------------------------- |
|
361 |
|
362 Class: CStifLogger |
|
363 |
|
364 Method: WriteDelimiter |
|
365 |
|
366 Description: Log a 16 bit delimiter. |
|
367 |
|
368 Log a delimiters required locations to the log information. |
|
369 This will be used if parameters are not given when calling this method. |
|
370 |
|
371 Parameters: const TDesC& aDelimiter: in: Logged delimiter(e.g. '#' or 'XO') |
|
372 TInt aCount: in: Repeated count for delimiter |
|
373 |
|
374 Return Values: TInt: Symbian error code. |
|
375 |
|
376 Errors/Exceptions: TDesLoggerOverflowHandler called if logged information |
|
377 is over KMaxLogData. |
|
378 |
|
379 Status: Approved |
|
380 |
|
381 ------------------------------------------------------------------------------- |
|
382 */ |
|
383 EXPORT_C TInt CStifLogger::WriteDelimiter(const TDesC& aDelimiter, |
|
384 TInt aCount) |
|
385 { |
|
386 TLogInfo delimiter; |
|
387 |
|
388 // Create overflow handler. If the delimiter size expands over the |
|
389 // KMaxLogData the TDesLoggerOverflowHandler will call. |
|
390 TDesSTFLoggerOverflowHandler overFlowHandler(iLogger, 3); |
|
391 |
|
392 // Create a delimiter |
|
393 for (TInt a = 0; a < aCount; a++) |
|
394 { |
|
395 // If delimiter creation keeps under the KMaxLogData. |
|
396 // If not we use TDesLoggerOverflowHandler. |
|
397 if ((a * aDelimiter.Length()) < KMaxLogData) |
|
398 { |
|
399 delimiter.Append(aDelimiter); |
|
400 } |
|
401 // KMaxLogData is exceeded |
|
402 else |
|
403 { |
|
404 // If the title size is over the KMaxLogData default delimiter will |
|
405 // use. Use normal overflowhandler to print overflow information. |
|
406 TBuf<4> empty; // Not really used. |
|
407 overFlowHandler.Overflow(empty); |
|
408 delimiter.Copy( |
|
409 _L( "##################################################" )); |
|
410 break; |
|
411 } |
|
412 } |
|
413 |
|
414 // No text style info |
|
415 return iLogger->Log(ENoStyle, delimiter); |
|
416 |
|
417 } |
|
418 |
|
419 /* |
|
420 ------------------------------------------------------------------------------- |
|
421 |
|
422 Class: CStifLogger |
|
423 |
|
424 Method: WriteDelimiter |
|
425 |
|
426 Description: Log a 8 bit delimiter. |
|
427 |
|
428 Log a delimiters required locations to the log information. |
|
429 |
|
430 Parameters: const TDesC8& aDelimiter: in: Logged delimiter |
|
431 (e.g. '#' or 'XO') |
|
432 TInt aCount: in: Repeated count for delimiter |
|
433 |
|
434 Return Values: TInt: Symbian error code. |
|
435 |
|
436 Errors/Exceptions: TDes8LoggerOverflowHandler called if logged information is |
|
437 over KMaxLogData. |
|
438 |
|
439 Status: Approved |
|
440 |
|
441 ------------------------------------------------------------------------------- |
|
442 */ |
|
443 EXPORT_C TInt CStifLogger::WriteDelimiter(const TDesC8& aDelimiter, |
|
444 TInt aCount) |
|
445 { |
|
446 TLogInfo8 delimiter; |
|
447 |
|
448 // Create overflow handler. If the delimiter size expands over the |
|
449 // KMaxLogData the TDesLoggerOverflowHandler will call. |
|
450 TDes8STFLoggerOverflowHandler overFlowHandler(iLogger, 3); |
|
451 |
|
452 // Create a delimiter |
|
453 for (TInt a = 0; a < aCount; a++) |
|
454 { |
|
455 // If delimiter creation keeps under the KMaxLogData. |
|
456 // If not we use TDesLoggerOverflowHandler. |
|
457 if ((a * aDelimiter.Length()) < KMaxLogData) |
|
458 { |
|
459 delimiter.Append(aDelimiter); |
|
460 } |
|
461 // KMaxLogData is exceeded |
|
462 else |
|
463 { |
|
464 // If the title size is over the KMaxLogData default delimiter will |
|
465 // use. Use normal overflowhandler to print overflow information. |
|
466 TBuf8<4> empty; // Not really used. |
|
467 overFlowHandler.Overflow(empty); |
|
468 delimiter.Copy( |
|
469 _L8( "##################################################" )); |
|
470 break; |
|
471 } |
|
472 } |
|
473 |
|
474 // No text style info |
|
475 return iLogger->Log(ENoStyle, delimiter); |
|
476 |
|
477 } |
|
478 |
|
479 /* |
|
480 ------------------------------------------------------------------------------- |
|
481 |
|
482 Class: CStifLogger |
|
483 |
|
484 Method: SaveData |
|
485 |
|
486 Description: Save file or data( 16 bit ). |
|
487 |
|
488 Used when is need to save file or data to storage e.g. web page. |
|
489 |
|
490 Parameters: TDesC& aData: in: Data to be saved |
|
491 |
|
492 Return Values: TInt: Symbian error code. |
|
493 |
|
494 Errors/Exceptions: None |
|
495 |
|
496 Status: Approved |
|
497 |
|
498 ------------------------------------------------------------------------------- |
|
499 */ |
|
500 EXPORT_C TInt CStifLogger::SaveData(TDesC& aData) |
|
501 { |
|
502 // No text style info |
|
503 return iLogger->Log(ENoStyle, aData); |
|
504 |
|
505 } |
|
506 |
|
507 /* |
|
508 ------------------------------------------------------------------------------- |
|
509 |
|
510 Class: CStifLogger |
|
511 |
|
512 Method: SaveData |
|
513 |
|
514 Description: Save file or data( 8 bit ). |
|
515 |
|
516 Used when is need to save file or data to storage e.g. web page. |
|
517 |
|
518 Parameters: TDesC8& aData: in: Data to be saved |
|
519 |
|
520 Return Values: TInt: Symbian error code. |
|
521 |
|
522 Errors/Exceptions: None |
|
523 |
|
524 Status: Approved |
|
525 |
|
526 ------------------------------------------------------------------------------- |
|
527 */ |
|
528 EXPORT_C TInt CStifLogger::SaveData(TDesC8& aData) |
|
529 { |
|
530 // No text style info |
|
531 return iLogger->Log(ENoStyle, aData); |
|
532 |
|
533 } |
|
534 |
|
535 /* |
|
536 ------------------------------------------------------------------------------- |
|
537 |
|
538 Class: CStifLogger |
|
539 |
|
540 Method: CreationResult |
|
541 |
|
542 Description: Return StifLogger creation result. |
|
543 |
|
544 Parameters: None |
|
545 |
|
546 Return Values: StifLogger creation result |
|
547 |
|
548 Errors/Exceptions: None |
|
549 |
|
550 Status: Approved |
|
551 |
|
552 ------------------------------------------------------------------------------- |
|
553 */ |
|
554 EXPORT_C TInt CStifLogger::CreationResult() |
|
555 { |
|
556 TInt outputType; |
|
557 iLogger->CreationResult(outputType); |
|
558 return outputType; |
|
559 } |
|
560 |
|
561 /* |
|
562 ------------------------------------------------------------------------------- |
|
563 |
|
564 Class: CStifLogger |
|
565 |
|
566 Method: OutputType |
|
567 |
|
568 Description: Get output type. Valid only if CreationResult returns KErrNone. |
|
569 |
|
570 Parameters: TOutput& aOutput |
|
571 |
|
572 Return Values: StifLogger creation result |
|
573 |
|
574 Errors/Exceptions: None |
|
575 |
|
576 Status: Approved |
|
577 |
|
578 ------------------------------------------------------------------------------- |
|
579 */ |
|
580 EXPORT_C CStifLogger::TOutput CStifLogger::OutputType() |
|
581 { |
|
582 |
|
583 TOutput outputType; |
|
584 iLogger->OutputType(outputType); |
|
585 return outputType; |
|
586 |
|
587 } |
|
588 |
|
589 EXPORT_C TInt CStifLogger::Send(TInt aStyle, const TDesC& aData) |
|
590 { |
|
591 return iLogger->Log(aStyle, aData); |
|
592 } |
|
593 |
|
594 EXPORT_C TInt CStifLogger::Send(TInt aStyle, const TDesC8& aData) |
|
595 { |
|
596 return iLogger->Log(aStyle, aData); |
|
597 } |
|
598 |
|
599 // End of File |
|
600 |