Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1021137
  • 博文数量: 326
  • 博客积分: 10135
  • 博客等级: 上将
  • 技术积分: 2490
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-22 23:53
文章分类

全部博文(326)

文章存档

2014年(1)

2012年(4)

2011年(1)

2010年(4)

2009年(41)

2008年(44)

2007年(63)

2006年(168)

我的朋友

分类:

2007-03-05 10:02:06

Need to debug some code on a mobile or track the execution flow ? The RFileLogger may help you. As a matter of fact this class is really powerful and easy to use.

The first step is to declare a connection to the file logger server and create the log file:


// Open a connection to the File logger server
RFileLogger iLog;
iLog.Connect();
iLog.CreateLog(_L("MyLoggingDirectory"),_L("MyLogFile"),EFileLoggingModeOverwrite);

...

// Close the log file and the connection to the server.
iLog.CloseLog();
iLog.Close();

The CreateLog function takes three parameter:
  the base name of the log directory (relative to C:\Logs and without trailing ’/’)
  the name of the log file
  the logging mode (EFileLoggingModeOverwrite or EFileLoggingModeAppend)

In the exemple code above, the full path to my log file (on the phone file system) would be C:/Logs/MyLoggingDirectory/MyLogFile.

As far as I am concerned, I like to put the opening code in the ConstructL() method of the class I want to trace, and the closing code in the destructor. Also note that in real production code, you would better check that Connect() and CreateLog() does return KErrNone.

Once you have done this, you can output text and data to the log file. The basic primitives are:

Primitive Output in the log file
iLog.Write(_L("Hello World")) 11/07/2003 4:00:13 Hello World
iLog.WriteFormat(_L("Result=%d"),err) 11/07/2003 4:00:13 Result=0
iLog.HexDump(aHeader,aHeader,myPtr,4) 11/07/2003 4:00:13 myBuf:0000: 41 42 00 44 AB.D

If you don’t want to have date or time logged, you can turn it off by using:

iLog.SetDateAndTime(TBool aUseDate, TBool aUseTime).

Don’t forget to add the flogger.lib in your MMP file and to include the flogger.h file, and that’s it. You can compile, execute and get your log file.

No ? The log file was not created! You’re right. This is not (yet) an issue with your code. But another specificity of how Symbian handles log file: nothing will be logged unless you manually create the C:/Logs/MyLoggingDirectory by yourself. No need to recompile anything to enable/disable the log feature. Just create or not logging directory [1]. I like this (but it has a cost in term of code size).

阅读(1051) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~