1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericservices/taskscheduler/SCHSVR/SSCH_UTL.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,195 @@
1.4 +// Copyright (c) 2004-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 +// User includes
1.20 +#include "SchLogger.h"
1.21 +
1.22 +#ifdef __SCHLOGGING__
1.23 +
1.24 +
1.25 +
1.26 +
1.27 +//
1.28 +// ------> CSheduleServerLog (source)
1.29 +//
1.30 +
1.31 +CSheduleServerLog::CSheduleServerLog()
1.32 + {
1.33 + }
1.34 +
1.35 +CSheduleServerLog::~CSheduleServerLog()
1.36 + {
1.37 + iFile.Close();
1.38 + iFs.Close();
1.39 + }
1.40 +
1.41 +void CSheduleServerLog::ConstructL(const TDesC& aLogFileName)
1.42 + {
1.43 + // Literal constants
1.44 + _LIT(KScheduleServerLoggingDirectoryE, "E:\\Logs\\SchSvr\\");
1.45 + _LIT(KScheduleServerLoggingDirectoryD, "D:\\Logs\\SchSvr\\");
1.46 + _LIT(KScheduleServerLoggingDirectory, "_:\\Logs\\SchSvr\\");
1.47 +
1.48 + User::LeaveIfError(iFs.Connect());
1.49 + TFileName logFile;
1.50 +
1.51 + // Log to drive D if possible
1.52 + TInt error = iFs.MkDirAll(KScheduleServerLoggingDirectoryE);
1.53 + if (error == KErrAlreadyExists || error == KErrNone)
1.54 + {
1.55 + logFile.Append(KScheduleServerLoggingDirectoryE);
1.56 + }
1.57 + else
1.58 + {
1.59 + error = iFs.MkDirAll(KScheduleServerLoggingDirectoryD);
1.60 + if (error == KErrAlreadyExists || error == KErrNone)
1.61 + {
1.62 + logFile.Append(KScheduleServerLoggingDirectoryD);
1.63 + }
1.64 + else
1.65 + {
1.66 + // system drive directory
1.67 + TBuf<15> loggingDirOnSysDrive(KScheduleServerLoggingDirectory);
1.68 + loggingDirOnSysDrive[0] = 'A' + static_cast<TInt>(RFs::GetSystemDrive());
1.69 +
1.70 + error = iFs.MkDirAll(loggingDirOnSysDrive);
1.71 + if (error != KErrAlreadyExists && error < KErrNone)
1.72 + User::Leave(error);
1.73 + logFile.Append(loggingDirOnSysDrive);
1.74 + }
1.75 + }
1.76 +
1.77 + // Open log file
1.78 + TParsePtrC parser(aLogFileName);
1.79 + logFile.Append(parser.Name());
1.80 +
1.81 +#ifdef __WINS__
1.82 + logFile.Append(_L(".WINS"));
1.83 +#elif __MARM__
1.84 + logFile.Append(_L(".MARM"));
1.85 +#endif
1.86 +#ifdef _DEBUG
1.87 + logFile.Append(_L(".UDEB"));
1.88 +#else
1.89 + logFile.Append(_L(".UREL"));
1.90 +#endif
1.91 + logFile.Append(parser.Ext());
1.92 + logFile.Append(_L(".TXT"));
1.93 +
1.94 + User::LeaveIfError(iFile.Replace(iFs, logFile, EFileStreamText | EFileShareAny));
1.95 + SeekEnd();
1.96 +
1.97 + NewLine();
1.98 + NewLine();
1.99 + _LIT(KNewLogEntry, "=== NEW LOG ===");
1.100 + Write(KNewLogEntry);
1.101 + NewLine();
1.102 + }
1.103 +
1.104 +CSheduleServerLog* CSheduleServerLog::NewL(const TDesC& aLogFileName)
1.105 + {
1.106 + CSheduleServerLog* self = new(ELeave) CSheduleServerLog();
1.107 + CleanupStack::PushL(self);
1.108 + self->ConstructL(aLogFileName);
1.109 + CleanupStack::Pop();
1.110 + return self;
1.111 + }
1.112 +
1.113 +//
1.114 +//
1.115 +//
1.116 +
1.117 +void CSheduleServerLog::Log(TRefByValue<const TDesC> aFmt,...)
1.118 + {
1.119 + VA_LIST list;
1.120 + VA_START(list, aFmt);
1.121 +
1.122 + TBuf<1024> buf;
1.123 + buf.AppendFormatList(aFmt, list);
1.124 + WriteWithTimeStamp(buf);
1.125 + NewLine();
1.126 + }
1.127 +
1.128 +void CSheduleServerLog::LogList(TRefByValue<const TDesC> aFmt, VA_LIST aList)
1.129 + {
1.130 + TBuf<1024> buf;
1.131 + buf.AppendFormatList(aFmt, aList);
1.132 + WriteWithTimeStamp(buf);
1.133 + NewLine();
1.134 + }
1.135 +
1.136 +void CSheduleServerLog::SeekEnd()
1.137 + {
1.138 + TInt pos;
1.139 + iFile.Seek(ESeekEnd, pos);
1.140 + }
1.141 +
1.142 +//
1.143 +//
1.144 +//
1.145 +
1.146 +void CSheduleServerLog::Write(const TDesC& aText)
1.147 + {
1.148 + HBufC8* buf = HBufC8::New(aText.Length());
1.149 + if (!buf)
1.150 + return;
1.151 +
1.152 + TPtr8 pBuf(buf->Des());
1.153 +
1.154 + const TInt KTextLength = aText.Length();
1.155 + for(TInt i=0; i<KTextLength; i++)
1.156 + {
1.157 + if (aText[i] < 256)
1.158 + pBuf.Append(aText[i]);
1.159 + }
1.160 +
1.161 + // Ignore errors
1.162 + TInt error = iFile.Write(pBuf);
1.163 + delete buf;
1.164 + error = iFile.Flush();
1.165 + }
1.166 +
1.167 +void CSheduleServerLog::Write(const TDesC& aFmt, VA_LIST& aList)
1.168 + {
1.169 + TDes* buf = new TBuf<1000>;
1.170 + if (!buf)
1.171 + return;
1.172 + buf->AppendFormatList(aFmt, aList);
1.173 + Write(*buf);
1.174 + delete buf;
1.175 + }
1.176 +
1.177 +void CSheduleServerLog::WriteWithTimeStamp(const TDesC& aText)
1.178 + {
1.179 + TBuf<200> buf;
1.180 + TTime now;
1.181 + now.HomeTime();
1.182 + TDateTime dateTime;
1.183 + dateTime = now.DateTime();
1.184 + buf.Format(_L("%02d.%02d:%02d:%06d "), dateTime.Hour(), dateTime.Minute(), dateTime.Second(), dateTime.MicroSecond());
1.185 + Write(buf);
1.186 + Write(aText);
1.187 + }
1.188 +
1.189 +void CSheduleServerLog::NewLine()
1.190 + {
1.191 + TBuf<2> buf;
1.192 + buf.Append(0x0D);
1.193 + buf.Append(0x0A);
1.194 + Write(buf);
1.195 + }
1.196 +
1.197 +
1.198 +#endif