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 CHtmlLogger |
|
15 * class member functions. |
|
16 * |
|
17 */ |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32std.h> |
|
21 #include "HtmlLogger.h" |
|
22 #include "Output.h" |
|
23 #include "LoggerTracing.h" |
|
24 #include "LoggerOverFlow.h" |
|
25 |
|
26 // EXTERNAL DATA STRUCTURES |
|
27 // None |
|
28 |
|
29 // EXTERNAL FUNCTION PROTOTYPES |
|
30 // None |
|
31 |
|
32 // CONSTANTS |
|
33 // None |
|
34 |
|
35 // MACROS |
|
36 // None |
|
37 |
|
38 // LOCAL CONSTANTS AND MACROS |
|
39 // None |
|
40 |
|
41 // MODULE DATA STRUCTURES |
|
42 // None |
|
43 |
|
44 // LOCAL FUNCTION PROTOTYPES |
|
45 // None |
|
46 |
|
47 // FORWARD DECLARATIONS |
|
48 // None |
|
49 |
|
50 // ==================== LOCAL FUNCTIONS ======================================= |
|
51 // None |
|
52 |
|
53 // ================= MEMBER FUNCTIONS ========================================= |
|
54 |
|
55 /* |
|
56 ------------------------------------------------------------------------------- |
|
57 |
|
58 Class: CHtmlLogger |
|
59 |
|
60 Method: CHtmlLogger |
|
61 |
|
62 Description: Default constructor |
|
63 |
|
64 C++ default constructor can NOT contain any code, that |
|
65 might leave. |
|
66 |
|
67 Parameters: COutput* output: in: Output source |
|
68 const TDesC& aTestFile: in: Log filename |
|
69 TBool aThreadIdToLogFile: in: Indicator to thread id adding to |
|
70 end of the log file |
|
71 |
|
72 Return Values: None |
|
73 |
|
74 Errors/Exceptions: None |
|
75 |
|
76 Status: Approved |
|
77 |
|
78 ------------------------------------------------------------------------------- |
|
79 */ |
|
80 CHtmlLogger::CHtmlLogger( COutput* output, |
|
81 const TDesC& aTestFile, |
|
82 TBool aThreadIdToLogFile ) |
|
83 { |
|
84 iOutput = output; |
|
85 StartHtmlPage( aTestFile, aThreadIdToLogFile ); |
|
86 } |
|
87 |
|
88 |
|
89 /* |
|
90 ------------------------------------------------------------------------------- |
|
91 |
|
92 Class: CHtmlLogger |
|
93 |
|
94 Method: ConstructL |
|
95 |
|
96 Description: Symbian OS second phase constructor |
|
97 |
|
98 Symbian OS default constructor can leave. |
|
99 |
|
100 Parameters: None |
|
101 |
|
102 Return Values: None |
|
103 |
|
104 Errors/Exceptions: None |
|
105 |
|
106 Status: Approved |
|
107 |
|
108 ------------------------------------------------------------------------------- |
|
109 */ |
|
110 void CHtmlLogger::ConstructL() |
|
111 { |
|
112 |
|
113 } |
|
114 |
|
115 /* |
|
116 ------------------------------------------------------------------------------- |
|
117 |
|
118 Class: CHtmlLogger |
|
119 |
|
120 Method: NewL |
|
121 |
|
122 Description: Two-phased constructor. |
|
123 |
|
124 Parameters: const TDesC& aTestPath: in: Log path |
|
125 const TDesC& aTestFile: in: Log filename |
|
126 TLoggerType aLoggerType: in: File type |
|
127 TOutput aOutput: in: Output source |
|
128 TBool aOverWrite: in: For file overwrite |
|
129 TBool aWithTimeStamp: in: For timestamp |
|
130 TBool aWithLineBreak: in: For line break |
|
131 TBool aWithEventRanking: in: For events ranking to file |
|
132 TBool aThreadIdToLogFile: in: Indicator to thread id adding to |
|
133 end of the log file |
|
134 TBool aCreateLogDir: in: Indicator to directory creation |
|
135 TInt aStaticBufferSize |
|
136 TBool aUnicode: in: Indicator if file has to be in unicode format |
|
137 |
|
138 Return Values: CHtmlLogger*: pointer to CHtmlLogger object |
|
139 |
|
140 Errors/Exceptions: Leaves if called COutput::NewL method fails |
|
141 |
|
142 Status: Proposal |
|
143 |
|
144 ------------------------------------------------------------------------------- |
|
145 */ |
|
146 CHtmlLogger* CHtmlLogger::NewL( const TDesC& aTestPath, |
|
147 const TDesC& aTestFile, |
|
148 TLoggerType aLoggerType, |
|
149 TOutput aOutput, |
|
150 TBool aOverWrite, |
|
151 TBool aWithTimeStamp, |
|
152 TBool aWithLineBreak, |
|
153 TBool aWithEventRanking, |
|
154 TBool aThreadIdToLogFile, |
|
155 TBool aCreateLogDir, |
|
156 TInt aStaticBufferSize, |
|
157 TBool aUnicode ) |
|
158 { |
|
159 __TRACE( KInfo, ( _L( "STIFLOGGER: Creating html logger" ) ) ); |
|
160 |
|
161 // Create COutput object output |
|
162 COutput* output = COutput::NewL( aTestPath, |
|
163 aTestFile, |
|
164 aLoggerType, |
|
165 aOutput, |
|
166 aOverWrite, |
|
167 aWithTimeStamp, |
|
168 aWithLineBreak, |
|
169 aWithEventRanking, |
|
170 aThreadIdToLogFile, |
|
171 aCreateLogDir, |
|
172 aStaticBufferSize, |
|
173 aUnicode ); |
|
174 |
|
175 CleanupStack::PushL( output ); |
|
176 __ASSERT_ALWAYS( output != NULL, User::Leave( KErrNotFound ) ); |
|
177 // Create CTxtLogger object htmlLogger and bind to COutput |
|
178 CHtmlLogger* htmlLogger = new (ELeave) CHtmlLogger( output, |
|
179 aTestFile, |
|
180 aThreadIdToLogFile ); |
|
181 // HTML logger owns output object and it will be destroyed in STIFLogger |
|
182 // destructor. |
|
183 CleanupStack::Pop( output ); |
|
184 |
|
185 CleanupStack::PushL( htmlLogger ); |
|
186 htmlLogger->ConstructL(); |
|
187 CleanupStack::Pop( htmlLogger ); |
|
188 |
|
189 return htmlLogger; |
|
190 |
|
191 } |
|
192 |
|
193 /* |
|
194 ------------------------------------------------------------------------------- |
|
195 |
|
196 Class: CHtmlLogger |
|
197 |
|
198 Method: ~CHtmlLogger |
|
199 |
|
200 Description: Destructor |
|
201 |
|
202 Parameters: None |
|
203 |
|
204 Return Values: None |
|
205 |
|
206 Errors/Exceptions: None |
|
207 |
|
208 Status: Approved |
|
209 |
|
210 ------------------------------------------------------------------------------- |
|
211 */ |
|
212 CHtmlLogger::~CHtmlLogger() |
|
213 { |
|
214 |
|
215 EndHtmlPage(); |
|
216 |
|
217 } |
|
218 |
|
219 /* |
|
220 ------------------------------------------------------------------------------- |
|
221 |
|
222 Class: CHtmlLogger |
|
223 |
|
224 Method: StartHtmlPage |
|
225 |
|
226 Description: Initialize html page. |
|
227 |
|
228 Parameters: const TDesC& aTestFile: in: Log filename |
|
229 TBool aThreadIdToLogFile: in: Indicator to thread id adding to |
|
230 end of the log file |
|
231 |
|
232 Return Values: None |
|
233 |
|
234 Errors/Exceptions: TDesLoggerOverflowHandler called if logged data is |
|
235 over KMaxFileName. |
|
236 |
|
237 Status: Approved |
|
238 |
|
239 ------------------------------------------------------------------------------- |
|
240 */ |
|
241 void CHtmlLogger::StartHtmlPage( const TDesC& aTestFile, |
|
242 TBool aThreadIdToLogFile ) |
|
243 { |
|
244 TFileName title; |
|
245 |
|
246 // Create overflow handler. |
|
247 TDesLoggerOverflowHandler overFlowHandler( this, 4 ); |
|
248 |
|
249 // Title |
|
250 if( aTestFile.Length() < KMaxFileName ) |
|
251 { |
|
252 title.Append( aTestFile ); |
|
253 } |
|
254 else |
|
255 { |
|
256 // If the title size is over the KMaxFileName rest of the title |
|
257 // will cut. Use normal overflowhandler to print overflow information. |
|
258 TBuf<4> empty; // Not really used. |
|
259 overFlowHandler.Overflow( empty ); |
|
260 TPtrC cuttedtitle = aTestFile.Left( KMaxFileName ); |
|
261 title.Append( cuttedtitle ); |
|
262 } |
|
263 |
|
264 // Add Thread id to title if enough space and test file is given and |
|
265 // aThreadIdToLogFile is true |
|
266 if( title.Length() < ( KMaxFileName - 3 ) && aTestFile.Length() > 0 && |
|
267 aThreadIdToLogFile ) |
|
268 { |
|
269 title.Append( _L( "_" ) ); |
|
270 RThread threadHandle; // A handle to a thread |
|
271 TThreadId id = threadHandle.Id(); // Encapsulates the |
|
272 // Id of a thread |
|
273 // Appends id in hexadesimal format |
|
274 title.AppendFormat( _L( "%x" ), (TInt)id ); |
|
275 } |
|
276 |
|
277 // Html start tags to whole page and header section |
|
278 iOutput->Write( EFalse, EFalse, EFalse, |
|
279 _L8( "\n<html>\n<head>\n<title>" ) ); |
|
280 // Html file title |
|
281 iOutput->Write( EFalse, EFalse, EFalse, title ); |
|
282 // Html header section end tags and start tag to body section |
|
283 iOutput->Write( EFalse, EFalse, EFalse, |
|
284 _L8( "</title>\n</head>\n\n\n<body>\n" ) ); |
|
285 |
|
286 } |
|
287 |
|
288 /* |
|
289 ------------------------------------------------------------------------------- |
|
290 |
|
291 Class: CHtmlLogger |
|
292 |
|
293 Method: EndHtmlPage |
|
294 |
|
295 Description: Finalize html page. |
|
296 |
|
297 Parameters: None |
|
298 |
|
299 Return Values: None |
|
300 |
|
301 Errors/Exceptions: None |
|
302 |
|
303 Status: Approved |
|
304 |
|
305 ------------------------------------------------------------------------------- |
|
306 */ |
|
307 void CHtmlLogger::EndHtmlPage() |
|
308 { |
|
309 // Html page and body section end tags |
|
310 iOutput->Write( EFalse, EFalse, EFalse, |
|
311 _L8( "\n\n\n</html>\n</body>\n\n\n" ) ); |
|
312 |
|
313 } |
|
314 |
|
315 /* |
|
316 ------------------------------------------------------------------------------- |
|
317 |
|
318 Class: CHtmlLogger |
|
319 |
|
320 Method: StyleStarting |
|
321 |
|
322 Description: Start style information logging. |
|
323 |
|
324 Parameters: TInt aStyle: in: Style information |
|
325 TBool aTimeStamp: inout: Time stamp indicator |
|
326 TBool aEventRanking: inout: Event ranking indicator |
|
327 |
|
328 Return Values: None |
|
329 |
|
330 Errors/Exceptions: None |
|
331 |
|
332 Status: Approved |
|
333 |
|
334 ------------------------------------------------------------------------------- |
|
335 */ |
|
336 void CHtmlLogger::StyleStarting( TInt aStyle, TBool& aTimeStamp, |
|
337 TBool& aEventRanking ) |
|
338 { |
|
339 if ( 0x00020 <= aStyle || // ERed, 0x00020 => 32 |
|
340 0x00040 <= aStyle || // EImportant, 0x00040 => 64 |
|
341 0x00080 <= aStyle || // EWarning, 0x00080 => 128 |
|
342 0x00100 <= aStyle ) // EError, 0x00100 => 256 |
|
343 { |
|
344 iOutput->Write( EFalse, EFalse, EFalse, |
|
345 _L8( "<FONT COLOR='#FF0000'>" ) ); |
|
346 if ( 0x00100 <= aStyle ) |
|
347 { |
|
348 iOutput->Write( aTimeStamp, EFalse, aEventRanking, |
|
349 _L8( "ERROR..." ) ); |
|
350 aStyle -= 0x00100; |
|
351 aTimeStamp = EFalse; // Time stamp added no time stamp to the |
|
352 // forward operations |
|
353 aEventRanking = EFalse; // Event ranking added no event ranking |
|
354 // to the forward operations |
|
355 } |
|
356 if ( 0x00080 <= aStyle ) |
|
357 { |
|
358 iOutput->Write( aTimeStamp, EFalse, aEventRanking, |
|
359 _L8( "WARNING..." ) ); |
|
360 aStyle -= 0x00080; |
|
361 aTimeStamp = EFalse; // Time stamp added no time stamp to the |
|
362 // forward operations |
|
363 aEventRanking = EFalse; // Event ranking added no event ranking |
|
364 // to the forward operations |
|
365 } |
|
366 if ( 0x00040 <= aStyle ) |
|
367 { |
|
368 iOutput->Write( aTimeStamp, EFalse, aEventRanking, |
|
369 _L8( "IMPORTANT..." ) ); |
|
370 aStyle -= 0x00040; |
|
371 aTimeStamp = EFalse; // Time stamp added no time stamp to the |
|
372 // forward operations |
|
373 aEventRanking = EFalse; // Event ranking added no event ranking |
|
374 // to the forward operations |
|
375 } |
|
376 if ( 0x00020 <= aStyle ) |
|
377 { |
|
378 aStyle -= 0x00020; |
|
379 } |
|
380 } |
|
381 // EGreen, 0x00010 => 16 |
|
382 if ( 0x00010 <= aStyle ) |
|
383 { |
|
384 iOutput->Write( EFalse, EFalse, EFalse, |
|
385 _L8( "<FONT COLOR='#009900'>" ) ); |
|
386 aStyle -= 0x00010; |
|
387 } |
|
388 // EBlue, 0x00008 => 8 |
|
389 if ( 0x00008 <= aStyle ) |
|
390 { |
|
391 iOutput->Write( EFalse, EFalse, EFalse, |
|
392 _L8( "<FONT COLOR='#3333FF'>" ) ); |
|
393 aStyle -= 0x00008; |
|
394 } |
|
395 // EUnderline, 0x00004 => 4 |
|
396 if ( 0x00004 <= aStyle ) |
|
397 { |
|
398 iOutput->Write( EFalse, EFalse, EFalse, _L8( "<U>" ) ); |
|
399 aStyle -= 0x00004; |
|
400 } |
|
401 // ECursive, 0x00002 => 2 |
|
402 if ( 0x00002 <= aStyle ) |
|
403 { |
|
404 iOutput->Write( EFalse, EFalse, EFalse, _L8( "<I>" ) ); |
|
405 aStyle -= 0x00002; |
|
406 } |
|
407 // EBold, 0x00001 => 1 |
|
408 if ( 0x00001 <= aStyle ) |
|
409 { |
|
410 iOutput->Write( EFalse, EFalse, EFalse, _L8( "<B>" ) ); |
|
411 aStyle -= 0x00001; |
|
412 } |
|
413 |
|
414 } |
|
415 |
|
416 /* |
|
417 ------------------------------------------------------------------------------- |
|
418 |
|
419 Class: CHtmlLogger |
|
420 |
|
421 Method: StyleEnding |
|
422 |
|
423 Description: Ends style information logging. |
|
424 |
|
425 Parameters: TInt aStyle: in: Style information |
|
426 |
|
427 Return Values: None |
|
428 |
|
429 Errors/Exceptions: None |
|
430 |
|
431 Status: Approved |
|
432 |
|
433 ------------------------------------------------------------------------------- |
|
434 */ |
|
435 void CHtmlLogger::StyleEnding( TInt aStyle ) |
|
436 { |
|
437 if ( 0x00020 <= aStyle || // ERed, 0x00020 => 32 |
|
438 0x00040 <= aStyle || // EImportant, 0x00040 => 64 |
|
439 0x00080 <= aStyle || // EWarning, 0x00080 => 128 |
|
440 0x00100 <= aStyle ) // EError, 0x00100 => 256 |
|
441 { |
|
442 iOutput->Write( EFalse, EFalse, EFalse, _L8( "</FONT>" ) ); |
|
443 if ( 0x00100 <= aStyle ) |
|
444 { |
|
445 aStyle -= 0x00100; |
|
446 } |
|
447 if ( 0x00080 <= aStyle ) |
|
448 { |
|
449 aStyle -= 0x00080; |
|
450 } |
|
451 if ( 0x00040 <= aStyle ) |
|
452 { |
|
453 aStyle -= 0x00040; |
|
454 } |
|
455 if ( 0x00020 <= aStyle ) |
|
456 { |
|
457 aStyle -= 0x00020; |
|
458 } |
|
459 } |
|
460 // EGreen, 0x00010 => 16 |
|
461 if ( 0x00010 <= aStyle ) |
|
462 { |
|
463 iOutput->Write( EFalse, EFalse, EFalse, _L8( "</FONT>" ) ); |
|
464 aStyle -= 0x00010; |
|
465 } |
|
466 // EBlue, 0x00008 => 8 |
|
467 if ( 0x00008 <= aStyle ) |
|
468 { |
|
469 iOutput->Write( EFalse, EFalse, EFalse, _L8( "</FONT>" ) ); |
|
470 aStyle -= 0x00008; |
|
471 } |
|
472 // EUnderline, 0x00004 => 4 |
|
473 if ( 0x00004 <= aStyle ) |
|
474 { |
|
475 iOutput->Write( EFalse, EFalse, EFalse, _L8( "</U>" ) ); |
|
476 aStyle -= 0x00004; |
|
477 } |
|
478 // ECursive, 0x00002 => 2 |
|
479 if ( 0x00002 <= aStyle ) |
|
480 { |
|
481 iOutput->Write( EFalse, EFalse, EFalse, _L8( "</I>" ) ); |
|
482 aStyle -= 0x00002; |
|
483 } |
|
484 // EBold, 0x00001 => 1 |
|
485 if ( 0x00001 <= aStyle ) |
|
486 { |
|
487 iOutput->Write( EFalse, EFalse, EFalse, _L8( "</B>" ) ); |
|
488 aStyle -= 0x00001; |
|
489 } |
|
490 |
|
491 } |
|
492 |
|
493 /* |
|
494 ------------------------------------------------------------------------------- |
|
495 |
|
496 Class: CHtmlLogger |
|
497 |
|
498 Method: Send |
|
499 |
|
500 Description: Send style information and 16 bit data to the output module |
|
501 |
|
502 Parameters: TInt TStyle: in: Text forming |
|
503 const TDesC& aData: in: Data to be logged |
|
504 |
|
505 Return Values: TInt: Symbian error code. |
|
506 |
|
507 Errors/Exceptions: None |
|
508 |
|
509 Status: Approved |
|
510 |
|
511 ------------------------------------------------------------------------------- |
|
512 */ |
|
513 TInt CHtmlLogger::Send( TInt aStyle, const TDesC& aData ) |
|
514 { |
|
515 // Time stamp indicator |
|
516 TBool timestamp( ETrue ); |
|
517 // Event ranking indicator |
|
518 TBool eventranking( ETrue ); |
|
519 |
|
520 StyleStarting( aStyle, timestamp, eventranking ); |
|
521 |
|
522 TInt ret = iOutput->Write( timestamp, ETrue, eventranking, aData ); |
|
523 |
|
524 StyleEnding( aStyle ); |
|
525 |
|
526 return ret; |
|
527 |
|
528 } |
|
529 |
|
530 /* |
|
531 ------------------------------------------------------------------------------- |
|
532 |
|
533 Class: CHtmlLogger |
|
534 |
|
535 Method: Send |
|
536 |
|
537 Description: Send style information and 8 bit data to the output module |
|
538 |
|
539 Parameters: TInt TStyle: in: Text forming |
|
540 const TDesC8& aData: in: Data to be logged |
|
541 |
|
542 Return Values: TInt: Symbian error code. |
|
543 |
|
544 Errors/Exceptions: None |
|
545 |
|
546 Status: Approved |
|
547 |
|
548 ------------------------------------------------------------------------------- |
|
549 */ |
|
550 TInt CHtmlLogger::Send( TInt aStyle, const TDesC8& aData ) |
|
551 { |
|
552 // Time stamp indicator |
|
553 TBool timestamp( ETrue ); |
|
554 // Event ranking indicator |
|
555 TBool eventranking( ETrue ); |
|
556 |
|
557 StyleStarting( aStyle, timestamp, eventranking ); |
|
558 |
|
559 TInt ret = iOutput->Write( timestamp, ETrue, eventranking, aData ); |
|
560 |
|
561 StyleEnding( aStyle ); |
|
562 |
|
563 return ret; |
|
564 |
|
565 } |
|
566 |
|
567 // ================= OTHER EXPORTED FUNCTIONS ================================= |
|
568 // None |
|
569 |
|
570 // End of File |
|