sl@0
|
1 |
// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// Common code for all debug logging variants
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include "../SERVER/w32cmd.h"
|
sl@0
|
19 |
#include "DEBUGLOG.H"
|
sl@0
|
20 |
|
sl@0
|
21 |
//#define __LIMIT_LOGGING yes //These should be turned off for released code
|
sl@0
|
22 |
//#define __FORCE_ASCII yes
|
sl@0
|
23 |
|
sl@0
|
24 |
#if defined(__LIMIT_LOGGING)
|
sl@0
|
25 |
_LIT(limitLogging,"!!");
|
sl@0
|
26 |
#endif
|
sl@0
|
27 |
|
sl@0
|
28 |
_LIT(KDebugLogFound,"Found");
|
sl@0
|
29 |
_LIT(KDebugLogSearchedFor,"Searched for");
|
sl@0
|
30 |
|
sl@0
|
31 |
EXPORT_C CDebugLog::CDebugLog(CDebugLogDevice *aDevice) : iDevice(aDevice), iLevel(ELogEverything)
|
sl@0
|
32 |
{
|
sl@0
|
33 |
__DECLARE_NAME(_S("CDebugLog"));
|
sl@0
|
34 |
}
|
sl@0
|
35 |
|
sl@0
|
36 |
CDebugLog::~CDebugLog()
|
sl@0
|
37 |
{
|
sl@0
|
38 |
delete iDevice;
|
sl@0
|
39 |
}
|
sl@0
|
40 |
|
sl@0
|
41 |
EXPORT_C void CDebugLog::ConstructL(TBool aIsFirst, TDesC &aParams)
|
sl@0
|
42 |
{
|
sl@0
|
43 |
_LIT(LogLine,"=================");
|
sl@0
|
44 |
iDevice->ConstructL(aIsFirst, aParams);
|
sl@0
|
45 |
iPrevTime.HomeTime();
|
sl@0
|
46 |
iExtraLen=0; // Indicates don't print time part to log
|
sl@0
|
47 |
MiscMessage(LogLine);
|
sl@0
|
48 |
MiscMessage(_L("[Logging Enabled]"));
|
sl@0
|
49 |
TBuf<32> timeBuf;
|
sl@0
|
50 |
iPrevTime.FormatL(timeBuf,_L("[ %:0%H%:1%T%:2%S%.%*C2%:3 ]"));
|
sl@0
|
51 |
MiscMessage(timeBuf);
|
sl@0
|
52 |
MiscMessage(LogLine);
|
sl@0
|
53 |
}
|
sl@0
|
54 |
|
sl@0
|
55 |
void CDebugLog::CommandBuf(TInt aApp)
|
sl@0
|
56 |
{
|
sl@0
|
57 |
if (aApp==iLastApp)
|
sl@0
|
58 |
return;
|
sl@0
|
59 |
TPtrC text(iWsDecoder.CommandBuf(aApp));
|
sl@0
|
60 |
WriteToLog(text);
|
sl@0
|
61 |
iLastApp=aApp;
|
sl@0
|
62 |
}
|
sl@0
|
63 |
|
sl@0
|
64 |
void CDebugLog::Command(TInt aClass, TInt aOpcode, const TAny *aCmdData, TInt aHandle)
|
sl@0
|
65 |
{
|
sl@0
|
66 |
TPtrC text(iWsDecoder.Command(aClass, aOpcode, aCmdData, aHandle));
|
sl@0
|
67 |
if (text!=KNullDesC)
|
sl@0
|
68 |
WriteToLog(text);
|
sl@0
|
69 |
}
|
sl@0
|
70 |
|
sl@0
|
71 |
void CDebugLog::NewClient(TUint aConnectionHandle)
|
sl@0
|
72 |
{
|
sl@0
|
73 |
TPtrC text(iWsDecoder.NewClient(aConnectionHandle));
|
sl@0
|
74 |
WriteToLog(text,ELogImportant);
|
sl@0
|
75 |
}
|
sl@0
|
76 |
|
sl@0
|
77 |
void CDebugLog::Reply(TInt aData)
|
sl@0
|
78 |
{
|
sl@0
|
79 |
TPtrC text(iWsDecoder.CommandReply(aData));
|
sl@0
|
80 |
WriteToLog(text);
|
sl@0
|
81 |
}
|
sl@0
|
82 |
|
sl@0
|
83 |
void CDebugLog::ReplyBuf(const TDesC8 &aDes)
|
sl@0
|
84 |
{
|
sl@0
|
85 |
TPtrC text(iWsDecoder.CommandReplyBuf(aDes));
|
sl@0
|
86 |
if (text!=KNullDesC)
|
sl@0
|
87 |
WriteToLog(text);
|
sl@0
|
88 |
}
|
sl@0
|
89 |
|
sl@0
|
90 |
void CDebugLog::ReplyBuf(const TDesC16 &aDes)
|
sl@0
|
91 |
{
|
sl@0
|
92 |
TPtrC text(iWsDecoder.CommandReplyBuf(aDes));
|
sl@0
|
93 |
if (text!=KNullDesC)
|
sl@0
|
94 |
WriteToLog(text);
|
sl@0
|
95 |
}
|
sl@0
|
96 |
|
sl@0
|
97 |
void CDebugLog::SignalEvent(TInt aApp)
|
sl@0
|
98 |
{
|
sl@0
|
99 |
TPtrC text(iWsDecoder.SignalEvent(aApp));
|
sl@0
|
100 |
WriteToLog(text);
|
sl@0
|
101 |
}
|
sl@0
|
102 |
|
sl@0
|
103 |
void CDebugLog::Panic(TInt aApp, TInt aReason)
|
sl@0
|
104 |
{
|
sl@0
|
105 |
TPtrC text(iWsDecoder.Panic(aApp, aReason));
|
sl@0
|
106 |
WriteToLog(text,ELogImportant);
|
sl@0
|
107 |
}
|
sl@0
|
108 |
|
sl@0
|
109 |
void CDebugLog::MiscMessage(TInt aPriority,const TDesC &aFormat,TInt aParam)
|
sl@0
|
110 |
{
|
sl@0
|
111 |
if (aPriority>=iLevel)
|
sl@0
|
112 |
MiscMessage(aFormat,aParam);
|
sl@0
|
113 |
}
|
sl@0
|
114 |
|
sl@0
|
115 |
void CDebugLog::MiscMessage(const TDesC &aFormat,TInt aParam)
|
sl@0
|
116 |
{
|
sl@0
|
117 |
TPtrC text(iWsDecoder.MiscMessage(aFormat,aParam));
|
sl@0
|
118 |
WriteToLog(text,iLevel);
|
sl@0
|
119 |
}
|
sl@0
|
120 |
|
sl@0
|
121 |
void CDebugLog::IniFileSettingRead(TInt aScreen, const TDesC& aVarName, TBool aFound, const TDesC& aResult)
|
sl@0
|
122 |
{
|
sl@0
|
123 |
if (!aFound && (iLevel != ELogEverything))
|
sl@0
|
124 |
{ // nothing to print
|
sl@0
|
125 |
return;
|
sl@0
|
126 |
}
|
sl@0
|
127 |
|
sl@0
|
128 |
TBuf<256> buf;
|
sl@0
|
129 |
|
sl@0
|
130 |
buf.Format(_L("%S .ini setting { "), &(aFound ? KDebugLogFound() : KDebugLogSearchedFor()));
|
sl@0
|
131 |
|
sl@0
|
132 |
if (aScreen >= 0)
|
sl@0
|
133 |
{
|
sl@0
|
134 |
buf.AppendFormat(_L("Screen %i, "), aScreen);
|
sl@0
|
135 |
}
|
sl@0
|
136 |
else
|
sl@0
|
137 |
{
|
sl@0
|
138 |
buf.Append(_L("Default, "));
|
sl@0
|
139 |
}
|
sl@0
|
140 |
|
sl@0
|
141 |
if (aFound)
|
sl@0
|
142 |
{
|
sl@0
|
143 |
buf.AppendFormat(_L("\"%S\", \"%S\" }"), &aVarName, &aResult);
|
sl@0
|
144 |
}
|
sl@0
|
145 |
else
|
sl@0
|
146 |
{
|
sl@0
|
147 |
buf.AppendFormat(_L("\"%S\" }"), &aVarName);
|
sl@0
|
148 |
}
|
sl@0
|
149 |
|
sl@0
|
150 |
MiscMessage(buf);
|
sl@0
|
151 |
}
|
sl@0
|
152 |
|
sl@0
|
153 |
|
sl@0
|
154 |
void CDebugLog::WriteToLog(const TDesC &aDes,TInt aLevel/*=ELogEverything*/)
|
sl@0
|
155 |
{
|
sl@0
|
156 |
if (aLevel<iLevel)
|
sl@0
|
157 |
return;
|
sl@0
|
158 |
#if defined(__LIMIT_LOGGING)
|
sl@0
|
159 |
TBuf<8> start(limitLogging);
|
sl@0
|
160 |
if (start!=aDes.Left(start.Length()))
|
sl@0
|
161 |
return;
|
sl@0
|
162 |
#endif
|
sl@0
|
163 |
if (iErr==KErrNone)
|
sl@0
|
164 |
{
|
sl@0
|
165 |
TBuf<80> timeBuf;
|
sl@0
|
166 |
TTime time;
|
sl@0
|
167 |
time.HomeTime();
|
sl@0
|
168 |
TTimeIntervalMicroSeconds diff(time.MicroSecondsFrom(iPrevTime));
|
sl@0
|
169 |
TInt diffi = I64LOW(diff.Int64());
|
sl@0
|
170 |
//
|
sl@0
|
171 |
if (iExtraLen>0)
|
sl@0
|
172 |
timeBuf.Format(_L("%+ *p%d.%03d"),iExtraLen,diffi/1000000,(diffi%1000000)/1000);
|
sl@0
|
173 |
iExtraLen=74-aDes.Length();
|
sl@0
|
174 |
if (iExtraLen<1)
|
sl@0
|
175 |
iExtraLen=1;
|
sl@0
|
176 |
/* Old version, logs current time
|
sl@0
|
177 |
TBuf<256> buf(aDes);
|
sl@0
|
178 |
time.FormatL(timeBuf,_L("%:0%H%:1%T%:2%S%.%*C2%:3"));
|
sl@0
|
179 |
buf.Format(_L("%+ *p%S"),len,&timeBuf);
|
sl@0
|
180 |
*/
|
sl@0
|
181 |
#if defined(__FORCE_ASCII)
|
sl@0
|
182 |
TBuf8<80> timeBuf8;
|
sl@0
|
183 |
TBuf8<128> des8;
|
sl@0
|
184 |
timeBuf8.Copy(timeBuf);
|
sl@0
|
185 |
des8.Copy(aDes);
|
sl@0
|
186 |
TRAP(iErr,iDevice->WriteToLog8L(timeBuf8, des8));
|
sl@0
|
187 |
#else
|
sl@0
|
188 |
TRAP(iErr,iDevice->WriteToLogL(timeBuf, aDes));
|
sl@0
|
189 |
#endif
|
sl@0
|
190 |
iPrevTime.HomeTime();
|
sl@0
|
191 |
iLastApp=0;
|
sl@0
|
192 |
}
|
sl@0
|
193 |
}
|
sl@0
|
194 |
|
sl@0
|
195 |
|
sl@0
|
196 |
void CDebugLog::HeapDump()
|
sl@0
|
197 |
{
|
sl@0
|
198 |
_LIT(LogLine,"===========");
|
sl@0
|
199 |
MiscMessage(LogLine);
|
sl@0
|
200 |
TBuf<128> buf;
|
sl@0
|
201 |
TInt biggestblock;
|
sl@0
|
202 |
buf.Format(_L("Heap size=%d, available=%d, count=%d"),User::Heap().Size(),User::Heap().Available(biggestblock),User::Heap().Count());
|
sl@0
|
203 |
MiscMessage(buf);
|
sl@0
|
204 |
//
|
sl@0
|
205 |
MiscMessage(LogLine);
|
sl@0
|
206 |
//
|
sl@0
|
207 |
MiscMessage(LogLine);
|
sl@0
|
208 |
//
|
sl@0
|
209 |
// Plus profile information for now
|
sl@0
|
210 |
//
|
sl@0
|
211 |
LogProfiles();
|
sl@0
|
212 |
}
|
sl@0
|
213 |
|
sl@0
|
214 |
void CDebugLog::SetLoggingLevel(TInt aLevel)
|
sl@0
|
215 |
{
|
sl@0
|
216 |
iLevel=aLevel;
|
sl@0
|
217 |
}
|
sl@0
|
218 |
|
sl@0
|
219 |
void CDebugLog::AppendProfileNum(TDes &aDes, TInt aNum)
|
sl@0
|
220 |
{
|
sl@0
|
221 |
aDes.AppendFormat(_L("%d.%02d, "),aNum/1000000,(aNum%1000000)/10000);
|
sl@0
|
222 |
}
|
sl@0
|
223 |
|
sl@0
|
224 |
void CDebugLog::AppendProfileCount(TDes &aDes, TInt aNum)
|
sl@0
|
225 |
{
|
sl@0
|
226 |
aDes.AppendFormat(_L("[%d], "),aNum);
|
sl@0
|
227 |
}
|
sl@0
|
228 |
|
sl@0
|
229 |
void CDebugLog::LogProfiles()
|
sl@0
|
230 |
{
|
sl@0
|
231 |
}
|