First public contribution.
1 // Copyright (c) 1995-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Common code for all debug logging variants
18 #include "../SERVER/w32cmd.h"
21 //#define __LIMIT_LOGGING yes //These should be turned off for released code
22 //#define __FORCE_ASCII yes
24 #if defined(__LIMIT_LOGGING)
25 _LIT(limitLogging,"!!");
28 _LIT(KDebugLogFound,"Found");
29 _LIT(KDebugLogSearchedFor,"Searched for");
31 EXPORT_C CDebugLog::CDebugLog(CDebugLogDevice *aDevice) : iDevice(aDevice), iLevel(ELogEverything)
33 __DECLARE_NAME(_S("CDebugLog"));
36 CDebugLog::~CDebugLog()
41 EXPORT_C void CDebugLog::ConstructL(TBool aIsFirst, TDesC &aParams)
43 _LIT(LogLine,"=================");
44 iDevice->ConstructL(aIsFirst, aParams);
46 iExtraLen=0; // Indicates don't print time part to log
48 MiscMessage(_L("[Logging Enabled]"));
50 iPrevTime.FormatL(timeBuf,_L("[ %:0%H%:1%T%:2%S%.%*C2%:3 ]"));
55 void CDebugLog::CommandBuf(TInt aApp)
59 TPtrC text(iWsDecoder.CommandBuf(aApp));
64 void CDebugLog::Command(TInt aClass, TInt aOpcode, const TAny *aCmdData, TInt aHandle)
66 TPtrC text(iWsDecoder.Command(aClass, aOpcode, aCmdData, aHandle));
71 void CDebugLog::NewClient(TUint aConnectionHandle)
73 TPtrC text(iWsDecoder.NewClient(aConnectionHandle));
74 WriteToLog(text,ELogImportant);
77 void CDebugLog::Reply(TInt aData)
79 TPtrC text(iWsDecoder.CommandReply(aData));
83 void CDebugLog::ReplyBuf(const TDesC8 &aDes)
85 TPtrC text(iWsDecoder.CommandReplyBuf(aDes));
90 void CDebugLog::ReplyBuf(const TDesC16 &aDes)
92 TPtrC text(iWsDecoder.CommandReplyBuf(aDes));
97 void CDebugLog::SignalEvent(TInt aApp)
99 TPtrC text(iWsDecoder.SignalEvent(aApp));
103 void CDebugLog::Panic(TInt aApp, TInt aReason)
105 TPtrC text(iWsDecoder.Panic(aApp, aReason));
106 WriteToLog(text,ELogImportant);
109 void CDebugLog::MiscMessage(TInt aPriority,const TDesC &aFormat,TInt aParam)
111 if (aPriority>=iLevel)
112 MiscMessage(aFormat,aParam);
115 void CDebugLog::MiscMessage(const TDesC &aFormat,TInt aParam)
117 TPtrC text(iWsDecoder.MiscMessage(aFormat,aParam));
118 WriteToLog(text,iLevel);
121 void CDebugLog::IniFileSettingRead(TInt aScreen, const TDesC& aVarName, TBool aFound, const TDesC& aResult)
123 if (!aFound && (iLevel != ELogEverything))
124 { // nothing to print
130 buf.Format(_L("%S .ini setting { "), &(aFound ? KDebugLogFound() : KDebugLogSearchedFor()));
134 buf.AppendFormat(_L("Screen %i, "), aScreen);
138 buf.Append(_L("Default, "));
143 buf.AppendFormat(_L("\"%S\", \"%S\" }"), &aVarName, &aResult);
147 buf.AppendFormat(_L("\"%S\" }"), &aVarName);
154 void CDebugLog::WriteToLog(const TDesC &aDes,TInt aLevel/*=ELogEverything*/)
158 #if defined(__LIMIT_LOGGING)
159 TBuf<8> start(limitLogging);
160 if (start!=aDes.Left(start.Length()))
168 TTimeIntervalMicroSeconds diff(time.MicroSecondsFrom(iPrevTime));
169 TInt diffi = I64LOW(diff.Int64());
172 timeBuf.Format(_L("%+ *p%d.%03d"),iExtraLen,diffi/1000000,(diffi%1000000)/1000);
173 iExtraLen=74-aDes.Length();
176 /* Old version, logs current time
178 time.FormatL(timeBuf,_L("%:0%H%:1%T%:2%S%.%*C2%:3"));
179 buf.Format(_L("%+ *p%S"),len,&timeBuf);
181 #if defined(__FORCE_ASCII)
184 timeBuf8.Copy(timeBuf);
186 TRAP(iErr,iDevice->WriteToLog8L(timeBuf8, des8));
188 TRAP(iErr,iDevice->WriteToLogL(timeBuf, aDes));
190 iPrevTime.HomeTime();
196 void CDebugLog::HeapDump()
198 _LIT(LogLine,"===========");
199 MiscMessage(LogLine);
202 buf.Format(_L("Heap size=%d, available=%d, count=%d"),User::Heap().Size(),User::Heap().Available(biggestblock),User::Heap().Count());
205 MiscMessage(LogLine);
207 MiscMessage(LogLine);
209 // Plus profile information for now
214 void CDebugLog::SetLoggingLevel(TInt aLevel)
219 void CDebugLog::AppendProfileNum(TDes &aDes, TInt aNum)
221 aDes.AppendFormat(_L("%d.%02d, "),aNum/1000000,(aNum%1000000)/10000);
224 void CDebugLog::AppendProfileCount(TDes &aDes, TInt aNum)
226 aDes.AppendFormat(_L("[%d], "),aNum);
229 void CDebugLog::LogProfiles()