Hi, I want to make debug / log file, but I want to write it with the last write on the top of the file.
How to do that?
Thanks
Hi, I want to make debug / log file, but I want to write it with the last write on the top of the file.
How to do that?
Thanks
Using RFile ::TInt Write(TInt aPos, const TDesC8 &aDes);, you can specify aPos to be 0. If that doesn't suits your requirement then RFile::Seek() may also be used & then write to file.
RFile::Write(TInt aPos, const TDesC8 &aDes, TInt aLength) can help you. Try giving the value of aPos as 0.
EDIT: Sorry, I just posted without having a refresh of page. So, duplicate answer.
If you are using Create(), then it will replace the old contents with new one, so try using Replace() (if you are not using it till now).
I'm already using Replace at constructL
So what I'm doing is something like this
when I call function WriteLog twice... the log on first call replaced by the new logCode:void CMyClass::ConstructL() { ... iFileLog.Replace(CEikonEnv::Static()->FsSession(), _L("C:\\data\\Log.txt"), EFileWrite | EFileShareAny); ... } void CMyClass::WriteLog(const TDesC8& aText) { iFileLog.Write(0, aText); }
Try utilizing the seek() then, like this:
void CMyClass::WriteLog(const TDesC8& aText)
{
RFs fs;
RFile file;
User::LeaveIfError(fs.Connect());
User::LeaveIfError(file.Open(fs, _L("C:\\data\\Log.txt"), EFileWrite));
TInt pos = 0;
file.Seek( ESeekStart, pos);
file.Write( aDes);
file.Close();
fs.Close();
}
RFile::Replace always ends up with a brand new empty file, replacing any possible existing one.
There is no one-liner for keeping the old data, you need to combine Open and Create. If one of them fails, try the other. I found such code in #13 of http://www.developer.nokia.com/Commu...-this-function
Just noticed that you want to have the most recent line at the top.
Something likethenCode:2011-12-27 Log File createdText files do not support "insert" operation, so for this case the closest thing you can do is re-writing the entire file having the new line written first. Note that this approach costs a lot of memory and/or a lot of time and also causes significant wear to the flash memory of the devices.Code:2012-01-01 New Year 2011-12-27 Log File created
I do not suggest it in short. If you need the functionality for comfort reasons, it is a better choice to create a viewer application which can show you the log file in reverse order.
Thanks wizard_hu_, maybe I just ignore this try (yes, this functionality for comfort reason)
And keep writing like usually... the last log in the bottom
Thanks