|
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // This file implements the GSM Test Harness logging facility. |
|
15 // The script engine will log significant events during the |
|
16 // during the course of a test. |
|
17 // To turn on logging, created the folder C:\LOGS\ETEL. |
|
18 // Note that this logging facility uses the Thread Local Storage for a thread. |
|
19 // |
|
20 // |
|
21 |
|
22 /** |
|
23 @file |
|
24 */ |
|
25 |
|
26 #include "Te_LoopBackSLOGGER.H" |
|
27 |
|
28 #ifdef __LOGGER__ |
|
29 #ifdef __EXE__ |
|
30 CETelLogger* ScriptLoggerContext=NULL; |
|
31 #endif |
|
32 |
|
33 _LIT(KHayesLogFileName,"C:\\LOGS\\ETEL\\TsyLb.TXT"); |
|
34 _LIT(KHayesLogFolder,"C:\\LOGS\\ETEL\\"); |
|
35 |
|
36 const TUint KLogBufferSize=500; |
|
37 |
|
38 CETelLogger* CETelLogger::NewL() |
|
39 /** |
|
40 * 2 Phase Constructor |
|
41 * |
|
42 * This method creates an instance of CETelLogger. |
|
43 * |
|
44 * @leave Leaves if out-of-memory. |
|
45 * @return pointer to the instance of "CETelLogger". |
|
46 */ |
|
47 { |
|
48 CETelLogger* logger=new(ELeave) CETelLogger(); |
|
49 CleanupStack::PushL(logger); |
|
50 logger->ConstructL(); |
|
51 CleanupStack::Pop(); |
|
52 return logger; |
|
53 } |
|
54 |
|
55 CETelLogger::CETelLogger() : iValid(EFalse) |
|
56 /** |
|
57 * This method is the constructor for CETelLogger. |
|
58 * |
|
59 * @param None. |
|
60 * @return None. |
|
61 * @note Initializes private boolean "iValid" to False. |
|
62 */ |
|
63 {} |
|
64 |
|
65 void CETelLogger::ConstructL() |
|
66 /** |
|
67 * This method is used to implement the 2 Phase Constructor for CETelLogger. |
|
68 * This method sets up the logfile. |
|
69 * |
|
70 * @leave Leaves if file can not be created. |
|
71 * @note Logging does not take place if the logging directory has not been created. |
|
72 * \note In debug mode, the logfile is not deleted at start of new session, |
|
73 * \note the logging for each session will be appended to the previous logfile. |
|
74 */ |
|
75 { |
|
76 if (FolderExists()) |
|
77 { |
|
78 iFs.Connect(); |
|
79 TInt ret=KErrNone; |
|
80 #if !(defined (_DEBUG)) |
|
81 ret=iFs.Delete(KHayesLogFileName); |
|
82 if(ret==KErrNone || ret==KErrNotFound) |
|
83 ret=iFile.Create(iFs,KHayesLogFileName,EFileShareAny|EFileWrite); |
|
84 #else |
|
85 ret=iFile.Open(iFs,KHayesLogFileName,EFileShareAny|EFileWrite); |
|
86 if(ret!=KErrNone) |
|
87 ret=iFile.Create(iFs,KHayesLogFileName,EFileShareAny|EFileWrite); |
|
88 #endif |
|
89 if(ret==KErrNone) |
|
90 { |
|
91 iValid=ETrue; |
|
92 TInt aPos=0; |
|
93 iFile.Seek(ESeekEnd,aPos); |
|
94 ret=iFile.Write(_L8("----------New Log----------\015\012")); |
|
95 } |
|
96 } |
|
97 } |
|
98 |
|
99 void CETelLogger::Destruct() |
|
100 /** |
|
101 * This method is used to delete the instantion of CETelLogger. |
|
102 * |
|
103 * @param None. |
|
104 * @return None. |
|
105 * @note None. |
|
106 */ |
|
107 { |
|
108 #ifdef __EXE__ |
|
109 CETelLogger* context=ScriptLoggerContext; |
|
110 delete context; |
|
111 ScriptLoggerContext=NULL; |
|
112 #else |
|
113 CETelLogger* context=(CETelLogger*) Dll::Tls(); |
|
114 delete context; |
|
115 Dll::SetTls(NULL); |
|
116 #endif |
|
117 } |
|
118 |
|
119 CETelLogger::~CETelLogger() |
|
120 /** |
|
121 * This method is the Destructor for the CETelLogger class and as such, closes |
|
122 * the logfile. |
|
123 * |
|
124 * @param None. |
|
125 * @return None. |
|
126 * @note None. |
|
127 */ |
|
128 { |
|
129 if(iValid) |
|
130 iFile.Close(); |
|
131 iFs.Close(); |
|
132 } |
|
133 |
|
134 void CETelLogger::WriteL(const TDesC8& aText) |
|
135 /** |
|
136 * This is a static method that is used to write a record of information |
|
137 * into the logfile. This method is used to place a text string without |
|
138 * any variable arguments in the string of input into the logfile. If an |
|
139 * instance of the CETelLogger class does not exist, this method is used |
|
140 * to create it. This routine only creates one instance of CETelLogger |
|
141 * for each session. |
|
142 * |
|
143 * @param reference to the text string to be written into the logfile. |
|
144 * @leave Leaves when no memory to create CETelLogger. |
|
145 * @note This is a static method. |
|
146 * @note Logging does not take place if the logging directory does not exist. |
|
147 * @note The logfile is not deleted at start of a new test session, the |
|
148 * @note logging for each test session will be appended in the logfile. |
|
149 */ |
|
150 { |
|
151 #ifdef __EXE__ |
|
152 CETelLogger* context=ScriptLoggerContext; |
|
153 #else |
|
154 CETelLogger* context=(CETelLogger*) Dll::Tls(); |
|
155 #endif |
|
156 if(context==NULL) |
|
157 { |
|
158 context=CETelLogger::NewL(); |
|
159 #ifdef __EXE__ |
|
160 ScriptLoggerContext=context; |
|
161 #else |
|
162 Dll::SetTls(context); |
|
163 #endif |
|
164 } |
|
165 if(context->iValid) |
|
166 context->WriteRecord(aText); |
|
167 } |
|
168 |
|
169 void CETelLogger::Write(const TText8* aText) |
|
170 /** |
|
171 * Static method used as the entry point to write information into the logfile. |
|
172 * |
|
173 * @param pointer to the text string to be written into the logfile. |
|
174 * @return None. |
|
175 * @note This is a static method. |
|
176 */ |
|
177 { |
|
178 TPtrC8 text(aText); |
|
179 TRAP_IGNORE(WriteL(text)); |
|
180 } |
|
181 |
|
182 void CETelLogger::WriteFormat(TRefByValue<const TDesC8> aFmt,...) |
|
183 /** |
|
184 * This is a static method that is used to write a record of information |
|
185 * into the logfile. This method is used to place a text string with |
|
186 * one or more variable arguments in the string of input into the logfile. |
|
187 * If an instance of the CETelLogger class does not exist, this method is |
|
188 * used to create it. This routine only creates one instance of |
|
189 * CETelLogger for each session. |
|
190 * |
|
191 * @param variable argument list for the text and data in the string |
|
192 * @return None. |
|
193 * @note This is a static method. |
|
194 * @note Logging does not take place if the logging directory does not exist. |
|
195 * @note The logfile is not deleted at start of a new test session, the |
|
196 * @note logging for each test session will be appended in the logfile. |
|
197 */ |
|
198 { |
|
199 TBuf8<KLogBufferSize> buf; |
|
200 VA_LIST list; |
|
201 VA_START(list,aFmt); |
|
202 buf.FormatList(aFmt,list); |
|
203 TChar tmpchar; |
|
204 for(TInt i=0;i<buf.Length();i++) |
|
205 { |
|
206 tmpchar=buf[i]; |
|
207 if(!((tmpchar.IsPrint()) || (tmpchar=='\n') || (tmpchar=='\r') || (tmpchar=='\t'))) |
|
208 buf[i]='.'; |
|
209 } |
|
210 #ifdef __EXE__ |
|
211 CETelLogger* context=ScriptLoggerContext; |
|
212 #else |
|
213 CETelLogger* context=(CETelLogger*) Dll::Tls(); |
|
214 #endif |
|
215 if(context==NULL) |
|
216 { |
|
217 TRAP_IGNORE(context=CETelLogger::NewL()); // trap but ignore leaves |
|
218 #ifdef __EXE__ |
|
219 ScriptLoggerContext=context; |
|
220 #else |
|
221 Dll::SetTls(context); |
|
222 #endif |
|
223 } |
|
224 if(context->iValid) |
|
225 context->WriteRecord(buf); |
|
226 } |
|
227 |
|
228 void CETelLogger::WriteRecord(const TDesC8& aText) |
|
229 /** |
|
230 * This method is used to add date and time information to the text string |
|
231 * and input it as a record into the logfile. |
|
232 * |
|
233 * @param reference to the text string to be written into the logfile. |
|
234 * @return None. |
|
235 * @note This is a static method. |
|
236 */ |
|
237 { |
|
238 if(iValid) |
|
239 { |
|
240 TBuf8<KLogBufferSize> buf; |
|
241 TTime now; |
|
242 now.UniversalTime(); |
|
243 TDateTime dateTime; |
|
244 dateTime = now.DateTime(); |
|
245 buf.Format(_L8 ("%02d.%02d:%02d:%06d "),dateTime.Hour(),dateTime.Minute(),dateTime.Second(),dateTime.MicroSecond()); |
|
246 buf.AppendFormat(_L8("%S\015\012"),&aText); |
|
247 iFile.Write(buf); |
|
248 iFile.Flush(); |
|
249 } |
|
250 } |
|
251 |
|
252 TBool CETelLogger::FolderExists() |
|
253 /** |
|
254 * This method determines if the folder c:\logs\Etel exists. |
|
255 * |
|
256 * @param None. |
|
257 * @return boolean value of ETrue if folder and EFalse if folder does not exist. |
|
258 * @note This is a static method. |
|
259 */ |
|
260 { |
|
261 TUint n; |
|
262 iFs.Connect(); |
|
263 TInt ret=iFs.Att(KHayesLogFolder,n); |
|
264 iFs.Close(); |
|
265 |
|
266 if (ret==KErrNone) |
|
267 return ETrue; |
|
268 return EFalse; |
|
269 } |
|
270 |
|
271 #endif |