sl@0: // Copyright (c) 2004-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: // sl@0: sl@0: // User includes sl@0: #include "SchLogger.h" sl@0: sl@0: #ifdef __SCHLOGGING__ sl@0: sl@0: sl@0: sl@0: sl@0: // sl@0: // ------> CSheduleServerLog (source) sl@0: // sl@0: sl@0: CSheduleServerLog::CSheduleServerLog() sl@0: { sl@0: } sl@0: sl@0: CSheduleServerLog::~CSheduleServerLog() sl@0: { sl@0: iFile.Close(); sl@0: iFs.Close(); sl@0: } sl@0: sl@0: void CSheduleServerLog::ConstructL(const TDesC& aLogFileName) sl@0: { sl@0: // Literal constants sl@0: _LIT(KScheduleServerLoggingDirectoryE, "E:\\Logs\\SchSvr\\"); sl@0: _LIT(KScheduleServerLoggingDirectoryD, "D:\\Logs\\SchSvr\\"); sl@0: _LIT(KScheduleServerLoggingDirectory, "_:\\Logs\\SchSvr\\"); sl@0: sl@0: User::LeaveIfError(iFs.Connect()); sl@0: TFileName logFile; sl@0: sl@0: // Log to drive D if possible sl@0: TInt error = iFs.MkDirAll(KScheduleServerLoggingDirectoryE); sl@0: if (error == KErrAlreadyExists || error == KErrNone) sl@0: { sl@0: logFile.Append(KScheduleServerLoggingDirectoryE); sl@0: } sl@0: else sl@0: { sl@0: error = iFs.MkDirAll(KScheduleServerLoggingDirectoryD); sl@0: if (error == KErrAlreadyExists || error == KErrNone) sl@0: { sl@0: logFile.Append(KScheduleServerLoggingDirectoryD); sl@0: } sl@0: else sl@0: { sl@0: // system drive directory sl@0: TBuf<15> loggingDirOnSysDrive(KScheduleServerLoggingDirectory); sl@0: loggingDirOnSysDrive[0] = 'A' + static_cast(RFs::GetSystemDrive()); sl@0: sl@0: error = iFs.MkDirAll(loggingDirOnSysDrive); sl@0: if (error != KErrAlreadyExists && error < KErrNone) sl@0: User::Leave(error); sl@0: logFile.Append(loggingDirOnSysDrive); sl@0: } sl@0: } sl@0: sl@0: // Open log file sl@0: TParsePtrC parser(aLogFileName); sl@0: logFile.Append(parser.Name()); sl@0: sl@0: #ifdef __WINS__ sl@0: logFile.Append(_L(".WINS")); sl@0: #elif __MARM__ sl@0: logFile.Append(_L(".MARM")); sl@0: #endif sl@0: #ifdef _DEBUG sl@0: logFile.Append(_L(".UDEB")); sl@0: #else sl@0: logFile.Append(_L(".UREL")); sl@0: #endif sl@0: logFile.Append(parser.Ext()); sl@0: logFile.Append(_L(".TXT")); sl@0: sl@0: User::LeaveIfError(iFile.Replace(iFs, logFile, EFileStreamText | EFileShareAny)); sl@0: SeekEnd(); sl@0: sl@0: NewLine(); sl@0: NewLine(); sl@0: _LIT(KNewLogEntry, "=== NEW LOG ==="); sl@0: Write(KNewLogEntry); sl@0: NewLine(); sl@0: } sl@0: sl@0: CSheduleServerLog* CSheduleServerLog::NewL(const TDesC& aLogFileName) sl@0: { sl@0: CSheduleServerLog* self = new(ELeave) CSheduleServerLog(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aLogFileName); sl@0: CleanupStack::Pop(); sl@0: return self; sl@0: } sl@0: sl@0: // sl@0: // sl@0: // sl@0: sl@0: void CSheduleServerLog::Log(TRefByValue aFmt,...) sl@0: { sl@0: VA_LIST list; sl@0: VA_START(list, aFmt); sl@0: sl@0: TBuf<1024> buf; sl@0: buf.AppendFormatList(aFmt, list); sl@0: WriteWithTimeStamp(buf); sl@0: NewLine(); sl@0: } sl@0: sl@0: void CSheduleServerLog::LogList(TRefByValue aFmt, VA_LIST aList) sl@0: { sl@0: TBuf<1024> buf; sl@0: buf.AppendFormatList(aFmt, aList); sl@0: WriteWithTimeStamp(buf); sl@0: NewLine(); sl@0: } sl@0: sl@0: void CSheduleServerLog::SeekEnd() sl@0: { sl@0: TInt pos; sl@0: iFile.Seek(ESeekEnd, pos); sl@0: } sl@0: sl@0: // sl@0: // sl@0: // sl@0: sl@0: void CSheduleServerLog::Write(const TDesC& aText) sl@0: { sl@0: HBufC8* buf = HBufC8::New(aText.Length()); sl@0: if (!buf) sl@0: return; sl@0: sl@0: TPtr8 pBuf(buf->Des()); sl@0: sl@0: const TInt KTextLength = aText.Length(); sl@0: for(TInt i=0; i; sl@0: if (!buf) sl@0: return; sl@0: buf->AppendFormatList(aFmt, aList); sl@0: Write(*buf); sl@0: delete buf; sl@0: } sl@0: sl@0: void CSheduleServerLog::WriteWithTimeStamp(const TDesC& aText) sl@0: { sl@0: TBuf<200> buf; sl@0: TTime now; sl@0: now.HomeTime(); sl@0: TDateTime dateTime; sl@0: dateTime = now.DateTime(); sl@0: buf.Format(_L("%02d.%02d:%02d:%06d "), dateTime.Hour(), dateTime.Minute(), dateTime.Second(), dateTime.MicroSecond()); sl@0: Write(buf); sl@0: Write(aText); sl@0: } sl@0: sl@0: void CSheduleServerLog::NewLine() sl@0: { sl@0: TBuf<2> buf; sl@0: buf.Append(0x0D); sl@0: buf.Append(0x0A); sl@0: Write(buf); sl@0: } sl@0: sl@0: sl@0: #endif