1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/loggingservices/eventlogger/LogServ/src/LogServPanic.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,158 @@
1.4 +// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include "logservpanic.h"
1.20 +#include "LogServSqlStrings.h"
1.21 +
1.22 +//
1.23 +// RMessage::Panic() also completes the message. This is:
1.24 +// (a) important for efficient cleanup within the kernel
1.25 +// (b) a problem if the message is completed a second time
1.26 +//
1.27 +void PanicClientL(const RMessage2& aMessage, TLogServPanic aPanic)
1.28 + {
1.29 + aMessage.Panic(KLogServ, aPanic);
1.30 + User::Leave(KLogPanicLeave);
1.31 + }
1.32 +
1.33 +void PanicClient(const RMessage2& aMessage, TLogServPanic aPanic)
1.34 + {
1.35 + aMessage.Panic(KLogServ, aPanic);
1.36 + }
1.37 +
1.38 +#pragma BullseyeCoverage off
1.39 +
1.40 +void Panic(TLogServPanic aPanic)
1.41 + {
1.42 + User::Panic(KLogServ, aPanic);
1.43 + }
1.44 +
1.45 +#pragma BullseyeCoverage on
1.46 +
1.47 +#ifdef LOGGING_ENABLED
1.48 +
1.49 +const TInt KLogEngLogBufferSize = 256;
1.50 +
1.51 +void Log::New()
1.52 + {
1.53 + _LIT(KNewLogText, "===== NEW LOG =====");
1.54 + //
1.55 + RFileLogger logger;
1.56 + TInt ret=logger.Connect();
1.57 + if (ret==KErrNone)
1.58 + {
1.59 + logger.CreateLog(KLogFolder, KLogFileName, EFileLoggingModeOverwrite);
1.60 + logger.Write(KNewLogText);
1.61 + }
1.62 + logger.Close();
1.63 + }
1.64 +
1.65 +void Log::Write(const TDesC& aText)
1.66 + {
1.67 + PruneLogFile();
1.68 +
1.69 + RFileLogger logger;
1.70 + TInt ret=logger.Connect();
1.71 + if (ret==KErrNone)
1.72 + {
1.73 + logger.SetDateAndTime(EFalse,EFalse);
1.74 + logger.CreateLog(KLogFolder, KLogFileName,EFileLoggingModeAppend);
1.75 + TBuf<KLogEngLogBufferSize> buf;
1.76 +
1.77 + // The debug log uses hometime rather than UTC for its timestamps. This is
1.78 + // purely a debugging aid.
1.79 + TTime now;
1.80 + now.HomeTime();
1.81 + TDateTime dateTime;
1.82 + dateTime = now.DateTime();
1.83 + buf.Format(KTimeFormat,dateTime.Hour(),dateTime.Minute(),dateTime.Second(),dateTime.MicroSecond());
1.84 + buf.AppendFormat(KTextFormat,&aText);
1.85 +
1.86 + logger.Write(buf);
1.87 + }
1.88 +
1.89 + logger.Close();
1.90 + }
1.91 +
1.92 +void Log::WriteFormat(TRefByValue<const TDesC> aFmt,...)
1.93 + {
1.94 + VA_LIST list;
1.95 + VA_START(list,aFmt);
1.96 +
1.97 + PruneLogFile();
1.98 +
1.99 + TBuf<2*KLogEngLogBufferSize> buf;
1.100 + buf.SetMax();
1.101 + buf.FillZ();
1.102 +
1.103 + // The debug log uses hometime rather than UTC for its timestamps. This is
1.104 + // purely a debugging aid.
1.105 + TTime now;
1.106 + now.HomeTime();
1.107 + TDateTime dateTime;
1.108 + dateTime = now.DateTime();
1.109 + buf.Format(KTimeFormat,dateTime.Hour(),dateTime.Minute(),dateTime.Second(),dateTime.MicroSecond());
1.110 + buf.AppendFormatList(aFmt, list );
1.111 +
1.112 + RFileLogger logger;
1.113 + TInt ret=logger.Connect();
1.114 + if (ret==KErrNone)
1.115 + {
1.116 + logger.SetDateAndTime(EFalse,EFalse);
1.117 + logger.CreateLog(KLogFolder, KLogFileName,EFileLoggingModeAppend);
1.118 + logger.Write(buf);
1.119 + }
1.120 +
1.121 + logger.Close();
1.122 +
1.123 + }
1.124 +
1.125 +void Log::PruneLogFile()
1.126 + {
1.127 + const TInt KMaxLogSize = 1024 * 500;
1.128 + //
1.129 + _LIT(KBaseFolder, "_:\\Logs\\");
1.130 + TFileName fileName(KBaseFolder);
1.131 + fileName[0] = 'A' + static_cast<TInt>(RFs::GetSystemDrive());
1.132 + fileName.Append(KLogFolder);
1.133 + fileName.Append(KPathDelimiter);
1.134 + fileName.Append(KLogFileName);
1.135 + //
1.136 + RFs fsSession;
1.137 + if (fsSession.Connect() == KErrNone)
1.138 + {
1.139 + TEntry entry;
1.140 + if (fsSession.Entry(fileName, entry) == KErrNone)
1.141 + {
1.142 + // Check size and delete if its too big
1.143 + if (entry.iSize >= KMaxLogSize)
1.144 + {
1.145 + TInt fileDeleteErr=fsSession.Delete(fileName);
1.146 + // If a debug build - record error
1.147 + #ifdef _DEBUG
1.148 + if (fileDeleteErr != KErrNone)
1.149 + {
1.150 + RDebug::Print(_L("Log::PruneLogFile - Failed to delete file. Error = %d"), fileDeleteErr);
1.151 + }
1.152 + #else
1.153 + (void)fileDeleteErr;
1.154 + #endif
1.155 + }
1.156 + }
1.157 + }
1.158 + fsSession.Close();
1.159 + }
1.160 +
1.161 +#endif