|
1 /* |
|
2 * Copyright (c) 2006-2007 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: Write log |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef C_CBCTESTLOGGER_H |
|
20 #define C_CBCTESTLOGGER_H |
|
21 |
|
22 #include <e32std.h> |
|
23 #include <e32base.h> |
|
24 #include <f32file.h> |
|
25 #include <apadef.h> |
|
26 |
|
27 class CEikonEnv; |
|
28 |
|
29 const TInt KLogNameLength = 64; |
|
30 const TInt KLogBufferLength = 512; |
|
31 |
|
32 _LIT( KLogRow80,"--------------------\r\n" ); |
|
33 _LIT( KLogLine, "\r\n" ); |
|
34 _LIT( KLogTwoLine, "\r\n\r\n" ); |
|
35 |
|
36 /** |
|
37 * Log class. The class will use CEikonEnv::Static, so we have to have the |
|
38 * App to use the class. |
|
39 */ |
|
40 class CBCTestLogger: public CBase |
|
41 { |
|
42 public: |
|
43 |
|
44 // constructor and destructor |
|
45 |
|
46 /** |
|
47 * Symbian second phase constructor |
|
48 */ |
|
49 static CBCTestLogger* NewL( CEikonEnv* aEikonEnv ); |
|
50 |
|
51 /** |
|
52 * Destructor |
|
53 */ |
|
54 virtual ~CBCTestLogger(); |
|
55 |
|
56 // new functions |
|
57 |
|
58 /** |
|
59 * Write custom text to log file. |
|
60 * @param aLogText, custom text. |
|
61 */ |
|
62 void WriteLogL(const TDesC& aLogText); |
|
63 |
|
64 /** |
|
65 * Write custom text to main log file. |
|
66 * @param aLogText, custom text |
|
67 */ |
|
68 void WriteMainLogL( const TDesC& aLogText ); |
|
69 |
|
70 /** |
|
71 * Get the buffer for formated text. |
|
72 */ |
|
73 TDes& Buffer(); |
|
74 |
|
75 /** |
|
76 * Creates time stamp for log file |
|
77 * @param aBuf, the time stamp will be appended to aBuf. |
|
78 */ |
|
79 void CreateTimeStamp( TDes& aBuf ); |
|
80 |
|
81 /** |
|
82 * Get the caption of application |
|
83 */ |
|
84 const TDesC& AppCaption(); |
|
85 |
|
86 protected: |
|
87 |
|
88 // constructor |
|
89 |
|
90 /** |
|
91 * C++ default constructor |
|
92 */ |
|
93 CBCTestLogger( CEikonEnv* aEikonEnv ); |
|
94 |
|
95 /** |
|
96 * Symbian 2nd phase constructor. |
|
97 */ |
|
98 void ConstructL(); |
|
99 |
|
100 // new functions |
|
101 |
|
102 /** |
|
103 * Write text to file. |
|
104 * @param aFile a reference of RFile to an opened file |
|
105 * @param aText the text to be written |
|
106 */ |
|
107 void WriteToFileL( RFile& aFile, const TDesC& aText ); |
|
108 |
|
109 private: |
|
110 |
|
111 /** |
|
112 * Create main log file. If the file is existed and has been modifed |
|
113 * recently, new log will be appended to the end of the file. If the |
|
114 * file is existed and has not been modified in recent two days, the |
|
115 * file will be replaced. |
|
116 */ |
|
117 void CreateMainLogL(); |
|
118 |
|
119 private: // data |
|
120 |
|
121 /** |
|
122 * log file for autotest results |
|
123 */ |
|
124 TBuf<KLogNameLength> iAtLogFileName; |
|
125 |
|
126 /** |
|
127 * temp storage for log writing |
|
128 */ |
|
129 TBuf<KLogBufferLength> iBuf; |
|
130 |
|
131 /** |
|
132 * log file |
|
133 */ |
|
134 RFile iAtLogFile; |
|
135 |
|
136 /** |
|
137 * not own |
|
138 */ |
|
139 CEikonEnv* iEikEnv; |
|
140 |
|
141 /** |
|
142 * The caption of application |
|
143 */ |
|
144 TApaAppCaption iCaption; |
|
145 |
|
146 }; |
|
147 |
|
148 #endif // C_CBCTESTLOGGER_H |