sl@0: // Copyright (c) 2002-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: #include "logservpanic.h" sl@0: #include "LogServSqlStrings.h" sl@0: sl@0: // sl@0: // RMessage::Panic() also completes the message. This is: sl@0: // (a) important for efficient cleanup within the kernel sl@0: // (b) a problem if the message is completed a second time sl@0: // sl@0: void PanicClientL(const RMessage2& aMessage, TLogServPanic aPanic) sl@0: { sl@0: aMessage.Panic(KLogServ, aPanic); sl@0: User::Leave(KLogPanicLeave); sl@0: } sl@0: sl@0: void PanicClient(const RMessage2& aMessage, TLogServPanic aPanic) sl@0: { sl@0: aMessage.Panic(KLogServ, aPanic); sl@0: } sl@0: sl@0: #pragma BullseyeCoverage off sl@0: sl@0: void Panic(TLogServPanic aPanic) sl@0: { sl@0: User::Panic(KLogServ, aPanic); sl@0: } sl@0: sl@0: #pragma BullseyeCoverage on sl@0: sl@0: #ifdef LOGGING_ENABLED sl@0: sl@0: const TInt KLogEngLogBufferSize = 256; sl@0: sl@0: void Log::New() sl@0: { sl@0: _LIT(KNewLogText, "===== NEW LOG ====="); sl@0: // sl@0: RFileLogger logger; sl@0: TInt ret=logger.Connect(); sl@0: if (ret==KErrNone) sl@0: { sl@0: logger.CreateLog(KLogFolder, KLogFileName, EFileLoggingModeOverwrite); sl@0: logger.Write(KNewLogText); sl@0: } sl@0: logger.Close(); sl@0: } sl@0: sl@0: void Log::Write(const TDesC& aText) sl@0: { sl@0: PruneLogFile(); sl@0: sl@0: RFileLogger logger; sl@0: TInt ret=logger.Connect(); sl@0: if (ret==KErrNone) sl@0: { sl@0: logger.SetDateAndTime(EFalse,EFalse); sl@0: logger.CreateLog(KLogFolder, KLogFileName,EFileLoggingModeAppend); sl@0: TBuf buf; sl@0: sl@0: // The debug log uses hometime rather than UTC for its timestamps. This is sl@0: // purely a debugging aid. sl@0: TTime now; sl@0: now.HomeTime(); sl@0: TDateTime dateTime; sl@0: dateTime = now.DateTime(); sl@0: buf.Format(KTimeFormat,dateTime.Hour(),dateTime.Minute(),dateTime.Second(),dateTime.MicroSecond()); sl@0: buf.AppendFormat(KTextFormat,&aText); sl@0: sl@0: logger.Write(buf); sl@0: } sl@0: sl@0: logger.Close(); sl@0: } sl@0: sl@0: void Log::WriteFormat(TRefByValue aFmt,...) sl@0: { sl@0: VA_LIST list; sl@0: VA_START(list,aFmt); sl@0: sl@0: PruneLogFile(); sl@0: sl@0: TBuf<2*KLogEngLogBufferSize> buf; sl@0: buf.SetMax(); sl@0: buf.FillZ(); sl@0: sl@0: // The debug log uses hometime rather than UTC for its timestamps. This is sl@0: // purely a debugging aid. sl@0: TTime now; sl@0: now.HomeTime(); sl@0: TDateTime dateTime; sl@0: dateTime = now.DateTime(); sl@0: buf.Format(KTimeFormat,dateTime.Hour(),dateTime.Minute(),dateTime.Second(),dateTime.MicroSecond()); sl@0: buf.AppendFormatList(aFmt, list ); sl@0: sl@0: RFileLogger logger; sl@0: TInt ret=logger.Connect(); sl@0: if (ret==KErrNone) sl@0: { sl@0: logger.SetDateAndTime(EFalse,EFalse); sl@0: logger.CreateLog(KLogFolder, KLogFileName,EFileLoggingModeAppend); sl@0: logger.Write(buf); sl@0: } sl@0: sl@0: logger.Close(); sl@0: sl@0: } sl@0: sl@0: void Log::PruneLogFile() sl@0: { sl@0: const TInt KMaxLogSize = 1024 * 500; sl@0: // sl@0: _LIT(KBaseFolder, "_:\\Logs\\"); sl@0: TFileName fileName(KBaseFolder); sl@0: fileName[0] = 'A' + static_cast(RFs::GetSystemDrive()); sl@0: fileName.Append(KLogFolder); sl@0: fileName.Append(KPathDelimiter); sl@0: fileName.Append(KLogFileName); sl@0: // sl@0: RFs fsSession; sl@0: if (fsSession.Connect() == KErrNone) sl@0: { sl@0: TEntry entry; sl@0: if (fsSession.Entry(fileName, entry) == KErrNone) sl@0: { sl@0: // Check size and delete if its too big sl@0: if (entry.iSize >= KMaxLogSize) sl@0: { sl@0: TInt fileDeleteErr=fsSession.Delete(fileName); sl@0: // If a debug build - record error sl@0: #ifdef _DEBUG sl@0: if (fileDeleteErr != KErrNone) sl@0: { sl@0: RDebug::Print(_L("Log::PruneLogFile - Failed to delete file. Error = %d"), fileDeleteErr); sl@0: } sl@0: #else sl@0: (void)fileDeleteErr; sl@0: #endif sl@0: } sl@0: } sl@0: } sl@0: fsSession.Close(); sl@0: } sl@0: sl@0: #endif