48
|
1 |
// Copyright (c) 2008-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 |
// System
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
/**
|
|
19 |
@file
|
|
20 |
@internalTechnology
|
|
21 |
|
|
22 |
*/
|
|
23 |
|
|
24 |
#include <e32base.h>
|
|
25 |
#include <e32debug.h>
|
|
26 |
#include <flogger.h>
|
|
27 |
|
|
28 |
// Component
|
|
29 |
#include "supldevlogger.h"
|
|
30 |
|
|
31 |
|
|
32 |
const TInt KSuplDevLogMaxBufSize = 300;
|
|
33 |
_LIT(KTimeFormat, "%H:%T:%S.%C");
|
|
34 |
_LIT(KSuplDevLogFolder, "lbs");
|
|
35 |
_LIT(KSuplDevLogFile,"lbs.txt");
|
|
36 |
_LIT(KSuplDevLogError, "Error: ");
|
|
37 |
_LIT(KSuplDevLogWarning, "Warning: ");
|
|
38 |
_LIT(KSuplDevLogSep," | ");
|
|
39 |
|
|
40 |
const TInt KSuplHexDumpWidth=16;
|
|
41 |
_LIT(KSuplFirstFormatString,"%04x : ");
|
|
42 |
_LIT(KSuplSecondFormatString,"%02x ");
|
|
43 |
_LIT(KSuplThirdFormatString,"%c");
|
|
44 |
_LIT(KSuplThreeSpaces," ");
|
|
45 |
_LIT(KSuplTwoSpaces," ");
|
|
46 |
const TText KSuplFullStopChar='.';
|
|
47 |
|
|
48 |
// Declare structures which will hold variables on the heap.
|
|
49 |
typedef struct
|
|
50 |
{
|
|
51 |
TTime currentTime;
|
|
52 |
TBuf16<32> cTimeStr;
|
|
53 |
TFileName dirName;
|
|
54 |
TInt16 pos;
|
|
55 |
TUint64 procId;
|
|
56 |
TUint32 stackUsage;
|
|
57 |
}
|
|
58 |
TCreateLog16;
|
|
59 |
|
|
60 |
typedef struct
|
|
61 |
{
|
|
62 |
TTime currentTime;
|
|
63 |
TBuf8<32> cTimeStr8;
|
|
64 |
TBuf16<32> cTimeStr;
|
|
65 |
TFileName dirName;
|
|
66 |
TInt pos;
|
|
67 |
TUint64 procId;
|
|
68 |
TUint32 stackUsage;
|
|
69 |
}
|
|
70 |
TCreateLog8;
|
|
71 |
|
|
72 |
typedef struct
|
|
73 |
{
|
|
74 |
RThread localThread;
|
|
75 |
RProcess localProcess;
|
|
76 |
TFileName fName;
|
|
77 |
TInt16 pos;
|
|
78 |
}
|
|
79 |
TMessageProcessName;
|
|
80 |
|
|
81 |
//#define ENABLE_SUPL_DEV_LOGGER_RDEBUG
|
|
82 |
//-----------------------------------------------------------------------------
|
|
83 |
// SuplDevLogger
|
|
84 |
//-----------------------------------------------------------------------------
|
|
85 |
|
|
86 |
/** Static function, one parameter, overwrite the previous log
|
|
87 |
@param aFmt TDes string reference
|
|
88 |
*/
|
|
89 |
EXPORT_C void SuplDevLogger::OverWrite(const TDesC16& aFmt)
|
|
90 |
{
|
|
91 |
TInt stackInt = 0;
|
|
92 |
|
|
93 |
// Grab some meory off the heap, give up if no memory available.
|
|
94 |
RFileLogger *logger = new RFileLogger;
|
|
95 |
if (logger == NULL)
|
|
96 |
return;
|
|
97 |
|
|
98 |
RBuf16 txt;
|
|
99 |
TInt err = txt.Create(KSuplDevLogMaxBufSize);
|
|
100 |
if (err != KErrNone)
|
|
101 |
{
|
|
102 |
delete logger;
|
|
103 |
return;
|
|
104 |
}
|
|
105 |
|
|
106 |
err = logger->Connect();
|
|
107 |
if (err == KErrNone)
|
|
108 |
{
|
|
109 |
CreateLogTxt(ELogNormal, ELogP5, &stackInt, txt);
|
|
110 |
txt.Append(aFmt.Left(KSuplDevLogMaxBufSize - txt.Length()));
|
|
111 |
|
|
112 |
logger->CreateLog(KSuplDevLogFolder, KSuplDevLogFile, EFileLoggingModeOverwrite);
|
|
113 |
logger->SetDateAndTime(EFalse, EFalse);
|
|
114 |
logger->Write(txt);
|
|
115 |
|
|
116 |
#ifdef ENABLE_SUPL_DEV_LOGGER_RDEBUG
|
|
117 |
txt.Append(_L("\n\r"));
|
|
118 |
RDebug::RawPrint(txt);
|
|
119 |
#endif
|
|
120 |
}
|
|
121 |
logger->Close();
|
|
122 |
|
|
123 |
// Free up heap space
|
|
124 |
txt.Close();
|
|
125 |
delete logger;
|
|
126 |
}
|
|
127 |
|
|
128 |
/** Static function, one parameter
|
|
129 |
@param aPrior Log entry priority
|
|
130 |
@param aFmt TDes string reference
|
|
131 |
*/
|
|
132 |
EXPORT_C void SuplDevLogger::Write(TSuplLogType aType, TSuplLogPriority aPrior, TRefByValue<const TDesC16> aFmt, ...)
|
|
133 |
{
|
|
134 |
TInt stackInt = 0;
|
|
135 |
|
|
136 |
// Grab space on the heap for varibles we are going to need here.
|
|
137 |
RFileLogger *logger = new RFileLogger;
|
|
138 |
if (logger == NULL)
|
|
139 |
{
|
|
140 |
return;
|
|
141 |
}
|
|
142 |
|
|
143 |
TInt err = logger->Connect();
|
|
144 |
if (err == KErrNone)
|
|
145 |
{
|
|
146 |
VA_LIST list;
|
|
147 |
VA_START(list, aFmt);
|
|
148 |
RBuf16 strList;
|
|
149 |
err = strList.Create(KSuplDevLogMaxBufSize);
|
|
150 |
|
|
151 |
if (err == KErrNone)
|
|
152 |
{
|
|
153 |
strList.FormatList(aFmt, list);
|
|
154 |
VA_END(list);
|
|
155 |
|
|
156 |
RBuf16 txt;
|
|
157 |
err = txt.Create(KSuplDevLogMaxBufSize);
|
|
158 |
if (err == KErrNone)
|
|
159 |
{
|
|
160 |
CreateLogTxt(aType, aPrior, &stackInt, txt);
|
|
161 |
txt.Append(strList.Left(KSuplDevLogMaxBufSize - txt.Length()));
|
|
162 |
|
|
163 |
logger->CreateLog(KSuplDevLogFolder, KSuplDevLogFile, EFileLoggingModeAppend);
|
|
164 |
logger->SetDateAndTime(EFalse, EFalse);
|
|
165 |
logger->Write(txt);
|
|
166 |
|
|
167 |
#ifdef ENABLE_SUPL_DEV_LOGGER_RDEBUG
|
|
168 |
txt.Append(_L("\n\r"));
|
|
169 |
RDebug::RawPrint(txt);
|
|
170 |
#endif
|
|
171 |
|
|
172 |
txt.Close();
|
|
173 |
}
|
|
174 |
strList.Close();
|
|
175 |
}
|
|
176 |
}
|
|
177 |
|
|
178 |
logger->Close();
|
|
179 |
delete logger;
|
|
180 |
}
|
|
181 |
|
|
182 |
/** Static function to dump the hex data
|
|
183 |
@param aPrior Log entry priority
|
|
184 |
@param aPtr TUnit8 pointer to hex data
|
|
185 |
@param aLen length of hex data
|
|
186 |
*/
|
|
187 |
EXPORT_C void SuplDevLogger::HexDump(TSuplLogPriority aPrior, const TUint8 *aPtr, TInt aLen)
|
|
188 |
{
|
|
189 |
TInt stackInt = 0;
|
|
190 |
|
|
191 |
if (aPtr==NULL) // nothing to do
|
|
192 |
return;
|
|
193 |
|
|
194 |
RFileLogger* logger = new RFileLogger;
|
|
195 |
if (logger == NULL)
|
|
196 |
return;
|
|
197 |
|
|
198 |
TInt err = logger->Connect();
|
|
199 |
logger->CreateLog(KSuplDevLogFolder, KSuplDevLogFile, EFileLoggingModeAppend);
|
|
200 |
logger->SetDateAndTime(EFalse, EFalse);
|
|
201 |
|
|
202 |
RBuf buf;
|
|
203 |
err = buf.Create(KSuplDevLogMaxBufSize);
|
|
204 |
if (err == KErrNone)
|
|
205 |
{
|
|
206 |
RBuf8 temp;
|
|
207 |
err= temp.Create(KSuplDevLogMaxBufSize);
|
|
208 |
if (err == KErrNone)
|
|
209 |
{
|
|
210 |
RBuf8 prefix;
|
|
211 |
if (prefix.Create(KSuplDevLogMaxBufSize) == KErrNone)
|
|
212 |
{
|
|
213 |
CreateLogTxt(ELogNormal, aPrior, &stackInt, prefix);
|
|
214 |
|
|
215 |
TInt i=0;
|
|
216 |
while (aLen>0)
|
|
217 |
{
|
|
218 |
TInt n=(aLen>KSuplHexDumpWidth ? KSuplHexDumpWidth : aLen);
|
|
219 |
buf.Copy(prefix);
|
|
220 |
buf.AppendFormat(KSuplFirstFormatString,i);
|
|
221 |
|
|
222 |
TInt j;
|
|
223 |
for (j=0; j<n; j++)
|
|
224 |
buf.AppendFormat(KSuplSecondFormatString,aPtr[i+j]);
|
|
225 |
|
|
226 |
while (j++<KSuplHexDumpWidth)
|
|
227 |
buf.Append(KSuplThreeSpaces);
|
|
228 |
|
|
229 |
buf.Append(KSuplTwoSpaces);
|
|
230 |
for (j=0; j<n; j++)
|
|
231 |
buf.AppendFormat(KSuplThirdFormatString,(aPtr[i+j]<32 || aPtr[i+j]>126) ? KSuplFullStopChar : aPtr[i+j]);
|
|
232 |
|
|
233 |
logger->Write(buf);
|
|
234 |
|
|
235 |
#ifdef ENABLE_SUPL_DEV_LOGGER_RDEBUG
|
|
236 |
buf.Append(_L("\n\r"));
|
|
237 |
RDebug::RawPrint(buf);
|
|
238 |
#endif
|
|
239 |
|
|
240 |
buf.SetLength(0);
|
|
241 |
temp.SetLength(0);
|
|
242 |
aLen-=n;
|
|
243 |
i+=n;
|
|
244 |
}
|
|
245 |
prefix.Close();
|
|
246 |
}
|
|
247 |
temp.Close();
|
|
248 |
}
|
|
249 |
buf.Close();
|
|
250 |
} //end if buf created ok
|
|
251 |
|
|
252 |
logger->Close();
|
|
253 |
delete logger;
|
|
254 |
}
|
|
255 |
|
|
256 |
/** private function, create common log text
|
|
257 |
@param aPrior Log entry priority
|
|
258 |
@param aBuf The log prefix buffer
|
|
259 |
@internalTechnology
|
|
260 |
*/
|
|
261 |
void SuplDevLogger::CreateLogTxt(TSuplLogType aType, TSuplLogPriority aPrior, TInt* aStackPtr, TDes16& aBuf)
|
|
262 |
{
|
|
263 |
// Grab space on the heap for all the varibles we are going to need here.
|
|
264 |
TCreateLog16* vars = new TCreateLog16;
|
|
265 |
if (vars == NULL)
|
|
266 |
return;
|
|
267 |
|
|
268 |
vars->currentTime.UniversalTime();
|
|
269 |
TRAPD(err, vars->currentTime.FormatL(vars->cTimeStr, KTimeFormat));
|
|
270 |
if (err)
|
|
271 |
{
|
|
272 |
User::Panic(KSuplDevLogger, KErrNoMemory);
|
|
273 |
}
|
|
274 |
|
|
275 |
vars->dirName = RProcess().FileName();
|
|
276 |
vars->pos = vars->dirName.LocateReverse('\\') + 1;
|
|
277 |
TPtr16 fileName = vars->dirName.MidTPtr(vars->pos);
|
|
278 |
vars->procId = RProcess().Id();
|
|
279 |
|
|
280 |
aBuf.Append(vars->cTimeStr);
|
|
281 |
aBuf.Append(KSuplDevLogSep);
|
|
282 |
|
|
283 |
aBuf.Append(fileName);
|
|
284 |
aBuf.Append(KSuplDevLogSep);
|
|
285 |
|
|
286 |
aBuf.AppendFormat(_L16("%LX"),vars->procId);
|
|
287 |
aBuf.Append(KSuplDevLogSep);
|
|
288 |
|
|
289 |
aBuf.AppendFormat(_L16("P%d"),aPrior);
|
|
290 |
aBuf.Append(KSuplDevLogSep);
|
|
291 |
|
|
292 |
aBuf.AppendFormat(_L16("%08X"), aStackPtr);
|
|
293 |
aBuf.Append(KSuplDevLogSep);
|
|
294 |
|
|
295 |
if (aType == ELogError)
|
|
296 |
{
|
|
297 |
aBuf.Append(KSuplDevLogError);
|
|
298 |
}
|
|
299 |
else if (aType == ELogWarning)
|
|
300 |
{
|
|
301 |
aBuf.Append(KSuplDevLogWarning);
|
|
302 |
}
|
|
303 |
|
|
304 |
delete vars;
|
|
305 |
}
|
|
306 |
|
|
307 |
/** Static function, one parameter, overwrite the previous log
|
|
308 |
@param aFmt TDes string reference
|
|
309 |
*/
|
|
310 |
EXPORT_C void SuplDevLogger::OverWrite(const TDesC8& aFmt)
|
|
311 |
{
|
|
312 |
TInt stackInt = 0;
|
|
313 |
|
|
314 |
RFileLogger* logger = new RFileLogger;
|
|
315 |
if (logger == NULL)
|
|
316 |
return;
|
|
317 |
|
|
318 |
TInt err = logger->Connect();
|
|
319 |
if (err == KErrNone)
|
|
320 |
{
|
|
321 |
RBuf8 txt;
|
|
322 |
err = txt.Create(KSuplDevLogMaxBufSize);
|
|
323 |
|
|
324 |
if (err == KErrNone)
|
|
325 |
{
|
|
326 |
CreateLogTxt(ELogNormal, ELogP5, &stackInt, txt);
|
|
327 |
txt.Append(aFmt.Left(KSuplDevLogMaxBufSize - txt.Length()));
|
|
328 |
|
|
329 |
logger->CreateLog(KSuplDevLogFolder, KSuplDevLogFile, EFileLoggingModeOverwrite);
|
|
330 |
logger->SetDateAndTime(EFalse, EFalse);
|
|
331 |
logger->Write(txt);
|
|
332 |
|
|
333 |
#ifdef ENABLE_SUPL_DEV_LOGGER_RDEBUG
|
|
334 |
txt.Append(_L("\n\r"));
|
|
335 |
RDebug::RawPrint(txt);
|
|
336 |
#endif
|
|
337 |
|
|
338 |
txt.Close();
|
|
339 |
}
|
|
340 |
} // end if logger connect ok
|
|
341 |
|
|
342 |
logger->Close();
|
|
343 |
delete logger;
|
|
344 |
}
|
|
345 |
|
|
346 |
/** Static function, one parameter
|
|
347 |
@param aPrior Log entry priority
|
|
348 |
@param aFmt Log entry
|
|
349 |
*/
|
|
350 |
EXPORT_C void SuplDevLogger::Write(TSuplLogType aType, TSuplLogPriority aPrior, TRefByValue<const TDesC8> aFmt, ...)
|
|
351 |
{
|
|
352 |
TInt stackInt = 0;
|
|
353 |
|
|
354 |
RFileLogger* logger = new RFileLogger;
|
|
355 |
if (logger == NULL)
|
|
356 |
return;
|
|
357 |
|
|
358 |
TInt err = logger->Connect();
|
|
359 |
if (err == KErrNone)
|
|
360 |
{
|
|
361 |
VA_LIST list;
|
|
362 |
VA_START(list, aFmt);
|
|
363 |
|
|
364 |
RBuf8 strList;
|
|
365 |
err = strList.Create(KSuplDevLogMaxBufSize);
|
|
366 |
if (err == KErrNone)
|
|
367 |
{
|
|
368 |
strList.FormatList(aFmt, list);
|
|
369 |
VA_END(list);
|
|
370 |
|
|
371 |
RBuf8 txt;
|
|
372 |
err = txt.Create(KSuplDevLogMaxBufSize);
|
|
373 |
|
|
374 |
if (err == KErrNone)
|
|
375 |
{
|
|
376 |
CreateLogTxt(aType, aPrior, &stackInt, txt);
|
|
377 |
txt.Append(strList.Left(KSuplDevLogMaxBufSize - txt.Length()));
|
|
378 |
|
|
379 |
logger->CreateLog(KSuplDevLogFolder, KSuplDevLogFile, EFileLoggingModeAppend);
|
|
380 |
logger->SetDateAndTime(EFalse, EFalse);
|
|
381 |
logger->Write(txt);
|
|
382 |
|
|
383 |
#ifdef ENABLE_SUPL_DEV_LOGGER_RDEBUG
|
|
384 |
txt.Append(_L("\n\r"));
|
|
385 |
RDebug::RawPrint(txt);
|
|
386 |
#endif
|
|
387 |
|
|
388 |
txt.Close();
|
|
389 |
}
|
|
390 |
|
|
391 |
strList.Close();
|
|
392 |
} // end if strList memory alloc'd ok
|
|
393 |
|
|
394 |
} // end if logger connected ok
|
|
395 |
|
|
396 |
logger->Close();
|
|
397 |
delete logger;
|
|
398 |
}
|
|
399 |
|
|
400 |
/** private function, create common log text
|
|
401 |
@param aPrior Log entry priority
|
|
402 |
@param aBuf The log prefix buffer
|
|
403 |
@internalTechnology
|
|
404 |
*/
|
|
405 |
void SuplDevLogger::CreateLogTxt(TSuplLogType aType, TSuplLogPriority aPrior, TInt* aStackPtr, TDes8& aBuf)
|
|
406 |
{
|
|
407 |
// Grab space on the heap for all the varibles we are going to need here.
|
|
408 |
TCreateLog8* vars = new TCreateLog8;
|
|
409 |
if (vars == NULL)
|
|
410 |
{
|
|
411 |
return;
|
|
412 |
}
|
|
413 |
|
|
414 |
vars->currentTime.UniversalTime();
|
|
415 |
TRAPD(err, vars->currentTime.FormatL(vars->cTimeStr, KTimeFormat));
|
|
416 |
if (err)
|
|
417 |
{
|
|
418 |
User::Panic(KSuplDevLogger, KErrNoMemory);
|
|
419 |
}
|
|
420 |
vars->cTimeStr8.Copy(vars->cTimeStr);
|
|
421 |
|
|
422 |
vars->dirName = RProcess().FileName();
|
|
423 |
vars->pos = vars->dirName.LocateReverse('\\') + 1;
|
|
424 |
TPtr fileName = vars->dirName.MidTPtr(vars->pos);
|
|
425 |
vars->procId = RProcess().Id();
|
|
426 |
|
|
427 |
aBuf.Append(vars->cTimeStr8);
|
|
428 |
aBuf.Append(KSuplDevLogSep);
|
|
429 |
|
|
430 |
aBuf.Append(fileName);
|
|
431 |
aBuf.Append(KSuplDevLogSep);
|
|
432 |
|
|
433 |
aBuf.AppendFormat(_L8("%LX"),vars->procId);
|
|
434 |
aBuf.Append(KSuplDevLogSep);
|
|
435 |
|
|
436 |
aBuf.AppendFormat(_L8("P%d"),aPrior);
|
|
437 |
aBuf.Append(KSuplDevLogSep);
|
|
438 |
|
|
439 |
aBuf.AppendFormat(_L8("%08X"), aStackPtr);
|
|
440 |
aBuf.Append(KSuplDevLogSep);
|
|
441 |
|
|
442 |
if (aType == ELogError)
|
|
443 |
{
|
|
444 |
aBuf.Append(KSuplDevLogError);
|
|
445 |
}
|
|
446 |
else if (aType == ELogWarning)
|
|
447 |
{
|
|
448 |
aBuf.Append(KSuplDevLogWarning);
|
|
449 |
}
|
|
450 |
|
|
451 |
delete vars;
|
|
452 |
}
|
|
453 |
|
|
454 |
/**
|
|
455 |
This function uses the message to get the process and thread information in
|
|
456 |
order to get the process name for the log file
|
|
457 |
@param aMessage Client\server message about to be completed
|
|
458 |
@param aName Contains the filename of the process to which this message belongs
|
|
459 |
**/
|
|
460 |
EXPORT_C void SuplDevLogger::GetMessageProcessName(const RMessage2& aMessage, TFileName& aName)
|
|
461 |
{
|
|
462 |
TMessageProcessName* vars = new TMessageProcessName;
|
|
463 |
if (vars == 0)
|
|
464 |
return;
|
|
465 |
|
|
466 |
//Get the thread and process information
|
|
467 |
if (aMessage.Client(vars->localThread) != KErrNone)
|
|
468 |
return;
|
|
469 |
|
|
470 |
vars->localThread.Process(vars->localProcess);
|
|
471 |
|
|
472 |
aName = vars->localProcess.FileName();
|
|
473 |
vars->pos = aName.LocateReverse('\\') + 1;
|
|
474 |
aName = aName.Mid(vars->pos);
|
|
475 |
|
|
476 |
delete vars;
|
|
477 |
|
|
478 |
return;
|
|
479 |
}
|