Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.
A simple Logger
A Simple Logger
Number of times we need a very simple file based logger, which can be used in debugging. Such logger is really helpful while understangin what exactly happening on target device when no remote debugging is possible. Its always useful if the logger is really lightweight and less complex. In following example, in Symbian C++, a very simple logger is presented with fewer lines.
A FileLogger class containing RFile object is present. The file name in which the contents will be logged is hard-coded on can replace it with there own logger file name. Numerous times the Logger file is fix and single. So purposefully a facility to set the filename through methods is avoided. One can customize the contructor to provide the file name.
This logger can be extended and can be changed as it has been provided in the most possible raw form. Basic code of opening file and adding a line to file has been presented. Also each line added gets tagged with the time and date.
The header file
void AddLog(TDes& aLine);
#endif /* FILELOGGER_H_ */
// TODO Auto-generated constructor stub
// TODO Auto-generated destructor stub
void FileLogger::AddLog(TDes& aLine)
TInt pos = 0;
time = now.DateTime();
temp.Format(_L("%d/%d/%d %d:%d:%d "),time.Day()+1,time.Month()+1,time.Year(),time.Hour(),time.Minute(),time.Second());
err = iFile.Open(fs,KFile, EFileWrite | EFileStreamText);
if(err == KErrNotFound)
err = iFile.Create(fs,KFile, EFileWrite | EFileStreamText);
Libary Reference Needed
efsrv.lib and charconv.lib