sl@0: // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Common code for all debug logging variants sl@0: // sl@0: // sl@0: sl@0: #include "../SERVER/w32cmd.h" sl@0: #include "DEBUGLOG.H" sl@0: sl@0: //#define __LIMIT_LOGGING yes //These should be turned off for released code sl@0: //#define __FORCE_ASCII yes sl@0: sl@0: #if defined(__LIMIT_LOGGING) sl@0: _LIT(limitLogging,"!!"); sl@0: #endif sl@0: sl@0: _LIT(KDebugLogFound,"Found"); sl@0: _LIT(KDebugLogSearchedFor,"Searched for"); sl@0: sl@0: EXPORT_C CDebugLog::CDebugLog(CDebugLogDevice *aDevice) : iDevice(aDevice), iLevel(ELogEverything) sl@0: { sl@0: __DECLARE_NAME(_S("CDebugLog")); sl@0: } sl@0: sl@0: CDebugLog::~CDebugLog() sl@0: { sl@0: delete iDevice; sl@0: } sl@0: sl@0: EXPORT_C void CDebugLog::ConstructL(TBool aIsFirst, TDesC &aParams) sl@0: { sl@0: _LIT(LogLine,"================="); sl@0: iDevice->ConstructL(aIsFirst, aParams); sl@0: iPrevTime.HomeTime(); sl@0: iExtraLen=0; // Indicates don't print time part to log sl@0: MiscMessage(LogLine); sl@0: MiscMessage(_L("[Logging Enabled]")); sl@0: TBuf<32> timeBuf; sl@0: iPrevTime.FormatL(timeBuf,_L("[ %:0%H%:1%T%:2%S%.%*C2%:3 ]")); sl@0: MiscMessage(timeBuf); sl@0: MiscMessage(LogLine); sl@0: } sl@0: sl@0: void CDebugLog::CommandBuf(TInt aApp) sl@0: { sl@0: if (aApp==iLastApp) sl@0: return; sl@0: TPtrC text(iWsDecoder.CommandBuf(aApp)); sl@0: WriteToLog(text); sl@0: iLastApp=aApp; sl@0: } sl@0: sl@0: void CDebugLog::Command(TInt aClass, TInt aOpcode, const TAny *aCmdData, TInt aHandle) sl@0: { sl@0: TPtrC text(iWsDecoder.Command(aClass, aOpcode, aCmdData, aHandle)); sl@0: if (text!=KNullDesC) sl@0: WriteToLog(text); sl@0: } sl@0: sl@0: void CDebugLog::NewClient(TUint aConnectionHandle) sl@0: { sl@0: TPtrC text(iWsDecoder.NewClient(aConnectionHandle)); sl@0: WriteToLog(text,ELogImportant); sl@0: } sl@0: sl@0: void CDebugLog::Reply(TInt aData) sl@0: { sl@0: TPtrC text(iWsDecoder.CommandReply(aData)); sl@0: WriteToLog(text); sl@0: } sl@0: sl@0: void CDebugLog::ReplyBuf(const TDesC8 &aDes) sl@0: { sl@0: TPtrC text(iWsDecoder.CommandReplyBuf(aDes)); sl@0: if (text!=KNullDesC) sl@0: WriteToLog(text); sl@0: } sl@0: sl@0: void CDebugLog::ReplyBuf(const TDesC16 &aDes) sl@0: { sl@0: TPtrC text(iWsDecoder.CommandReplyBuf(aDes)); sl@0: if (text!=KNullDesC) sl@0: WriteToLog(text); sl@0: } sl@0: sl@0: void CDebugLog::SignalEvent(TInt aApp) sl@0: { sl@0: TPtrC text(iWsDecoder.SignalEvent(aApp)); sl@0: WriteToLog(text); sl@0: } sl@0: sl@0: void CDebugLog::Panic(TInt aApp, TInt aReason) sl@0: { sl@0: TPtrC text(iWsDecoder.Panic(aApp, aReason)); sl@0: WriteToLog(text,ELogImportant); sl@0: } sl@0: sl@0: void CDebugLog::MiscMessage(TInt aPriority,const TDesC &aFormat,TInt aParam) sl@0: { sl@0: if (aPriority>=iLevel) sl@0: MiscMessage(aFormat,aParam); sl@0: } sl@0: sl@0: void CDebugLog::MiscMessage(const TDesC &aFormat,TInt aParam) sl@0: { sl@0: TPtrC text(iWsDecoder.MiscMessage(aFormat,aParam)); sl@0: WriteToLog(text,iLevel); sl@0: } sl@0: sl@0: void CDebugLog::IniFileSettingRead(TInt aScreen, const TDesC& aVarName, TBool aFound, const TDesC& aResult) sl@0: { sl@0: if (!aFound && (iLevel != ELogEverything)) sl@0: { // nothing to print sl@0: return; sl@0: } sl@0: sl@0: TBuf<256> buf; sl@0: sl@0: buf.Format(_L("%S .ini setting { "), &(aFound ? KDebugLogFound() : KDebugLogSearchedFor())); sl@0: sl@0: if (aScreen >= 0) sl@0: { sl@0: buf.AppendFormat(_L("Screen %i, "), aScreen); sl@0: } sl@0: else sl@0: { sl@0: buf.Append(_L("Default, ")); sl@0: } sl@0: sl@0: if (aFound) sl@0: { sl@0: buf.AppendFormat(_L("\"%S\", \"%S\" }"), &aVarName, &aResult); sl@0: } sl@0: else sl@0: { sl@0: buf.AppendFormat(_L("\"%S\" }"), &aVarName); sl@0: } sl@0: sl@0: MiscMessage(buf); sl@0: } sl@0: sl@0: sl@0: void CDebugLog::WriteToLog(const TDesC &aDes,TInt aLevel/*=ELogEverything*/) sl@0: { sl@0: if (aLevel start(limitLogging); sl@0: if (start!=aDes.Left(start.Length())) sl@0: return; sl@0: #endif sl@0: if (iErr==KErrNone) sl@0: { sl@0: TBuf<80> timeBuf; sl@0: TTime time; sl@0: time.HomeTime(); sl@0: TTimeIntervalMicroSeconds diff(time.MicroSecondsFrom(iPrevTime)); sl@0: TInt diffi = I64LOW(diff.Int64()); sl@0: // sl@0: if (iExtraLen>0) sl@0: timeBuf.Format(_L("%+ *p%d.%03d"),iExtraLen,diffi/1000000,(diffi%1000000)/1000); sl@0: iExtraLen=74-aDes.Length(); sl@0: if (iExtraLen<1) sl@0: iExtraLen=1; sl@0: /* Old version, logs current time sl@0: TBuf<256> buf(aDes); sl@0: time.FormatL(timeBuf,_L("%:0%H%:1%T%:2%S%.%*C2%:3")); sl@0: buf.Format(_L("%+ *p%S"),len,&timeBuf); sl@0: */ sl@0: #if defined(__FORCE_ASCII) sl@0: TBuf8<80> timeBuf8; sl@0: TBuf8<128> des8; sl@0: timeBuf8.Copy(timeBuf); sl@0: des8.Copy(aDes); sl@0: TRAP(iErr,iDevice->WriteToLog8L(timeBuf8, des8)); sl@0: #else sl@0: TRAP(iErr,iDevice->WriteToLogL(timeBuf, aDes)); sl@0: #endif sl@0: iPrevTime.HomeTime(); sl@0: iLastApp=0; sl@0: } sl@0: } sl@0: sl@0: sl@0: void CDebugLog::HeapDump() sl@0: { sl@0: _LIT(LogLine,"==========="); sl@0: MiscMessage(LogLine); sl@0: TBuf<128> buf; sl@0: TInt biggestblock; sl@0: buf.Format(_L("Heap size=%d, available=%d, count=%d"),User::Heap().Size(),User::Heap().Available(biggestblock),User::Heap().Count()); sl@0: MiscMessage(buf); sl@0: // sl@0: MiscMessage(LogLine); sl@0: // sl@0: MiscMessage(LogLine); sl@0: // sl@0: // Plus profile information for now sl@0: // sl@0: LogProfiles(); sl@0: } sl@0: sl@0: void CDebugLog::SetLoggingLevel(TInt aLevel) sl@0: { sl@0: iLevel=aLevel; sl@0: } sl@0: sl@0: void CDebugLog::AppendProfileNum(TDes &aDes, TInt aNum) sl@0: { sl@0: aDes.AppendFormat(_L("%d.%02d, "),aNum/1000000,(aNum%1000000)/10000); sl@0: } sl@0: sl@0: void CDebugLog::AppendProfileCount(TDes &aDes, TInt aNum) sl@0: { sl@0: aDes.AppendFormat(_L("[%d], "),aNum); sl@0: } sl@0: sl@0: void CDebugLog::LogProfiles() sl@0: { sl@0: }