748
|
1 |
// Copyright (c) 2006-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 the License "Symbian Foundation License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// lbstestlogger.cpp
|
|
15 |
// System
|
|
16 |
//
|
|
17 |
//
|
|
18 |
|
|
19 |
#include <e32base.h>
|
|
20 |
#include <e32debug.h>
|
|
21 |
#include <flogger.h>
|
|
22 |
#include <f32file.h>
|
|
23 |
|
|
24 |
// Component
|
|
25 |
#include "ctlbstestlogger.h"
|
|
26 |
|
|
27 |
const TInt KLbsDevLogMaxBufSize = 256;
|
|
28 |
_LIT(KTimeFormat, "%H:%T:%S.%C");
|
|
29 |
_LIT(KLogPath, "\\logs\\LbsTestLogs\\");
|
|
30 |
_LIT(KLbsDevLogFolder, "LbsTestLogs");
|
|
31 |
_LIT(KLbsDevLogFile,"lbstest.txt");
|
|
32 |
_LIT(KLbsDevLogError, "Error: ");
|
|
33 |
_LIT(KLbsDevLogWarning, "Warning: ");
|
|
34 |
_LIT(KLbsDevLogSep," | ");
|
|
35 |
_LIT(KLbsDevLog, "LbsDevLog");
|
|
36 |
|
|
37 |
|
|
38 |
const TInt KLbsHexDumpWidth=16;
|
|
39 |
_LIT(KLbsFirstFormatString,"%04x : ");
|
|
40 |
_LIT(KLbsSecondFormatString,"%02x ");
|
|
41 |
_LIT(KLbsThirdFormatString,"%c");
|
|
42 |
_LIT(KLbsThreeSpaces," ");
|
|
43 |
_LIT(KLbsTwoSpaces," ");
|
|
44 |
const TText KLbsFullStopChar='.';
|
|
45 |
|
|
46 |
//-----------------------------------------------------------------------------
|
|
47 |
// LbsTestLogger
|
|
48 |
//-----------------------------------------------------------------------------
|
|
49 |
|
|
50 |
void LbsTestLogger::CreateLogDir()
|
|
51 |
{
|
|
52 |
TInt err;
|
|
53 |
|
|
54 |
// Create the directory
|
|
55 |
RFs fs;
|
|
56 |
err = fs.Connect();
|
|
57 |
if(KErrNone == err)
|
|
58 |
{
|
|
59 |
err = fs.MkDirAll(KLogPath);
|
|
60 |
fs.Close();
|
|
61 |
}
|
|
62 |
}
|
|
63 |
|
|
64 |
|
|
65 |
/** Static function, one parameter
|
|
66 |
@param aPrior Log entry priority
|
|
67 |
@param aFmt TDes string reference
|
|
68 |
@InternalTechnology
|
|
69 |
@prototype
|
|
70 |
*/
|
|
71 |
void LbsTestLogger::Write(TLogType aType, TLogPriority aPrior, TRefByValue<const TDesC16> aFmt, ...)
|
|
72 |
{
|
|
73 |
RFileLogger logger;
|
|
74 |
TInt err = logger.Connect();
|
|
75 |
|
|
76 |
if (err == KErrNone)
|
|
77 |
{
|
|
78 |
VA_LIST list;
|
|
79 |
VA_START(list, aFmt);
|
|
80 |
TBuf16<KLbsDevLogMaxBufSize> strList;
|
|
81 |
strList.FormatList(aFmt, list);
|
|
82 |
VA_END(list);
|
|
83 |
TBuf16<KLbsDevLogMaxBufSize> txt;
|
|
84 |
|
|
85 |
CreateLogTxt(aType, aPrior, txt);
|
|
86 |
txt.Append(strList.Left(KLbsDevLogMaxBufSize - txt.Length()));
|
|
87 |
|
|
88 |
CreateLogDir();
|
|
89 |
|
|
90 |
logger.CreateLog(KLbsDevLogFolder, KLbsDevLogFile, EFileLoggingModeAppend);
|
|
91 |
logger.SetDateAndTime(EFalse, EFalse);
|
|
92 |
logger.Write(txt);
|
|
93 |
|
|
94 |
}
|
|
95 |
|
|
96 |
logger.Close();
|
|
97 |
}
|
|
98 |
|
|
99 |
/** Static function to dump the hex data
|
|
100 |
@param aPrior Log entry priority
|
|
101 |
@param aPtr TUnit8 pointer to hex data
|
|
102 |
@param aLen length of hex data
|
|
103 |
@InternalTechnology
|
|
104 |
@prototype
|
|
105 |
*/
|
|
106 |
void LbsTestLogger::HexDump(TLogPriority aPrior, const TUint8 *aPtr, TInt aLen)
|
|
107 |
{
|
|
108 |
if (aPtr==NULL) // nothing to do
|
|
109 |
return;
|
|
110 |
|
|
111 |
RFileLogger logger;
|
|
112 |
TInt err = logger.Connect();
|
|
113 |
CreateLogDir();
|
|
114 |
logger.CreateLog(KLbsDevLogFolder, KLbsDevLogFile, EFileLoggingModeAppend);
|
|
115 |
logger.SetDateAndTime(EFalse, EFalse);
|
|
116 |
|
|
117 |
// based on RFileLogger
|
|
118 |
TBuf<KLbsDevLogMaxBufSize> buf;
|
|
119 |
TBuf8<KLbsDevLogMaxBufSize> temp;
|
|
120 |
TInt i=0;
|
|
121 |
TBuf8<KLbsDevLogMaxBufSize> prefix;
|
|
122 |
CreateLogTxt(ELogNormal, aPrior, prefix);
|
|
123 |
|
|
124 |
while (aLen>0)
|
|
125 |
{
|
|
126 |
TInt n=(aLen>KLbsHexDumpWidth ? KLbsHexDumpWidth : aLen);
|
|
127 |
buf.Copy(prefix);
|
|
128 |
buf.AppendFormat(KLbsFirstFormatString,i);
|
|
129 |
|
|
130 |
TInt j;
|
|
131 |
for (j=0; j<n; j++)
|
|
132 |
buf.AppendFormat(KLbsSecondFormatString,aPtr[i+j]);
|
|
133 |
|
|
134 |
while (j++<KLbsHexDumpWidth)
|
|
135 |
buf.Append(KLbsThreeSpaces);
|
|
136 |
|
|
137 |
buf.Append(KLbsTwoSpaces);
|
|
138 |
for (j=0; j<n; j++)
|
|
139 |
buf.AppendFormat(KLbsThirdFormatString,(aPtr[i+j]<32 || aPtr[i+j]>126) ? KLbsFullStopChar : aPtr[i+j]);
|
|
140 |
|
|
141 |
logger.Write(buf);
|
|
142 |
|
|
143 |
buf.SetLength(0);
|
|
144 |
temp.SetLength(0);
|
|
145 |
aLen-=n;
|
|
146 |
i+=n;
|
|
147 |
}
|
|
148 |
|
|
149 |
logger.Close();
|
|
150 |
}
|
|
151 |
|
|
152 |
/** private function, create common log text
|
|
153 |
@param aPrior Log entry priority
|
|
154 |
@param aBuf The log prefix buffer
|
|
155 |
@InternalTechnology
|
|
156 |
@prototype
|
|
157 |
*/
|
|
158 |
void LbsTestLogger::CreateLogTxt(TLogType aType, TLogPriority aPrior, TDes16& aBuf)
|
|
159 |
{
|
|
160 |
TTime currentTime;
|
|
161 |
currentTime.UniversalTime();
|
|
162 |
TBuf16<32> cTimeStr;
|
|
163 |
TInt err = KErrNone;
|
|
164 |
TRAP(err, currentTime.FormatL(cTimeStr, KTimeFormat);)
|
|
165 |
if(err)
|
|
166 |
User::Panic(KLbsDevLog, err);
|
|
167 |
|
|
168 |
TFileName dirName = RProcess().FileName();
|
|
169 |
TInt16 pos = dirName.LocateReverse('\\') + 1;
|
|
170 |
TPtr16 fileName = dirName.MidTPtr(pos);
|
|
171 |
TUint64 procId = RProcess().Id().Id();
|
|
172 |
|
|
173 |
aBuf.Append(cTimeStr);
|
|
174 |
aBuf.Append(KLbsDevLogSep);
|
|
175 |
|
|
176 |
aBuf.Append(fileName);
|
|
177 |
aBuf.Append(KLbsDevLogSep);
|
|
178 |
|
|
179 |
//aBuf.AppendFormat(_L16("%LX"),procId);
|
|
180 |
//aBuf.Append(KLbsDevLogSep);
|
|
181 |
|
|
182 |
aBuf.AppendFormat(_L16("P%d"),aPrior);
|
|
183 |
aBuf.Append(KLbsDevLogSep);
|
|
184 |
|
|
185 |
if (aType == ELogError)
|
|
186 |
{
|
|
187 |
aBuf.Append(KLbsDevLogError);
|
|
188 |
}
|
|
189 |
else if (aType == ELogWarning)
|
|
190 |
{
|
|
191 |
aBuf.Append(KLbsDevLogWarning);
|
|
192 |
}
|
|
193 |
}
|
|
194 |
|
|
195 |
|
|
196 |
/** Static function, one parameter
|
|
197 |
@param aPrior Log entry priority
|
|
198 |
@param aFmt Log entry
|
|
199 |
@InternalTechnology
|
|
200 |
@prototype
|
|
201 |
*/
|
|
202 |
void LbsTestLogger::Write(TLogType aType, TLogPriority aPrior, TRefByValue<const TDesC8> aFmt, ...)
|
|
203 |
{
|
|
204 |
RFileLogger logger;
|
|
205 |
TInt err = logger.Connect();
|
|
206 |
|
|
207 |
if (err == KErrNone)
|
|
208 |
{
|
|
209 |
VA_LIST list;
|
|
210 |
VA_START(list, aFmt);
|
|
211 |
TBuf8<KLbsDevLogMaxBufSize> strList;
|
|
212 |
strList.FormatList(aFmt, list);
|
|
213 |
VA_END(list);
|
|
214 |
|
|
215 |
TBuf8<KLbsDevLogMaxBufSize> txt;
|
|
216 |
CreateLogTxt(aType, aPrior, txt);
|
|
217 |
txt.Append(strList.Left(KLbsDevLogMaxBufSize - txt.Length()));
|
|
218 |
|
|
219 |
CreateLogDir();
|
|
220 |
logger.CreateLog(KLbsDevLogFolder, KLbsDevLogFile, EFileLoggingModeAppend);
|
|
221 |
logger.SetDateAndTime(EFalse, EFalse);
|
|
222 |
logger.Write(txt);
|
|
223 |
|
|
224 |
}
|
|
225 |
|
|
226 |
logger.Close();
|
|
227 |
}
|
|
228 |
|
|
229 |
/** private function, create common log text
|
|
230 |
@param aPrior Log entry priority
|
|
231 |
@param aBuf The log prefix buffer
|
|
232 |
@InternalTechnology
|
|
233 |
@prototype
|
|
234 |
*/
|
|
235 |
void LbsTestLogger::CreateLogTxt(TLogType aType, TLogPriority aPrior, TDes8& aBuf)
|
|
236 |
{
|
|
237 |
TTime currentTime;
|
|
238 |
currentTime.UniversalTime();
|
|
239 |
TBuf<32> cTimeStr;
|
|
240 |
TInt err = KErrNone;
|
|
241 |
TRAP(err, currentTime.FormatL(cTimeStr, KTimeFormat);)
|
|
242 |
if(err)
|
|
243 |
User::Panic(KLbsDevLog, err);
|
|
244 |
|
|
245 |
TBuf8<32> cTimeStr8;
|
|
246 |
cTimeStr8.Copy(cTimeStr);
|
|
247 |
|
|
248 |
TFileName dirName = RProcess().FileName();
|
|
249 |
TInt pos = dirName.LocateReverse('\\') + 1;
|
|
250 |
TPtr fileName = dirName.MidTPtr(pos);
|
|
251 |
TUint64 procId = RProcess().Id().Id();
|
|
252 |
|
|
253 |
aBuf.Append(cTimeStr8);
|
|
254 |
aBuf.Append(KLbsDevLogSep);
|
|
255 |
|
|
256 |
aBuf.Append(fileName);
|
|
257 |
aBuf.Append(KLbsDevLogSep);
|
|
258 |
|
|
259 |
//aBuf.AppendFormat(_L8("%LX"),procId);
|
|
260 |
//aBuf.Append(KLbsDevLogSep);
|
|
261 |
|
|
262 |
aBuf.AppendFormat(_L8("P%d"),aPrior);
|
|
263 |
aBuf.Append(KLbsDevLogSep);
|
|
264 |
|
|
265 |
if (aType == ELogError)
|
|
266 |
{
|
|
267 |
aBuf.Append(KLbsDevLogError);
|
|
268 |
}
|
|
269 |
else if (aType == ELogWarning)
|
|
270 |
{
|
|
271 |
aBuf.Append(KLbsDevLogWarning);
|
|
272 |
}
|
|
273 |
}
|