zoukankan      html  css  js  c++  java
  • Symbian中使用日志类(RFileLogger)(转)

    一、首先要在使用日志类的文件include "flogger.h",然后再加入flogger.lib文件
    类RFileLogger对应的头文件和库文件分别是flogger.h和flogger.lib
    二、使用
    1、在类的二阶段构造ConstructL()中加上下面代码:
    //打开日志文件服务的连接
    RFileLogger iLog;
    iLog.Connect();
    iLog.CreateLog(_L("MyLoggingDirectory"),_L("MyLogFile"),EFileLoggingModeOverwrite);
    其中CreateLog函数有三个参数: Log路径 Log文件名 记录模式(EFileLoggingModeOverwrite|EFileLoggingModeAppend)
    上面代码,是我的log文件的full path(手机上的文件系统) C:/Logs/MyLoggingDirectory/MyLogFile.
    2、在类的析构函数中加入下面代码:
    //关闭log文件和服务器连接
    iLog.CloseLog();
    iLog.Close();
    3、向日志文件中输入文本和数据
    命令                                                                            Log文件
    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
    (以上步骤做完后进行编译可能会报错,提示iLog未找到定义,我是把RFileLogger iLog;这句写在*.cpp所对应的*.h文件中,再进行编译就ok了)
    如果不想记录日期和事件,可以使用这个函数来关闭:
    iLog.SetDateAndTime(TBool aUseDate, TBool aUseTime)
    三、注意:
    1、  以上是参考网上他人所写只是稍加改动
    2、  在模拟器上调试时(即日志文件文件创建在计算机上):
    这时,日志文件的目录应该是:C:\Symbian\7.0s\Series60_v21\Epoc32\wins\c\logs
    上面的代码实际上就是在这个目录里创建一个名字为MyLoggingDirectory的文件夹,并在这里面创建一个没有扩展名的日志文件MyLogFile。
    注意:文件夹MyLoggingDirectory必须由我们手动创建,但日志文件MyLogFile程序会给我们创建。如果没有创建这个文件夹,那么日志文件也就不会被创建了,但这时候程序也不会报错,只是得不到调试信息了而已。
    3、  在手机上调试时(即日志文件创建在手机上)

    Last edited by tjliying; 2008-09-24 at 04:00.
  • 相关阅读:
    LeetCode 88. Merge Sorted Array
    LeetCode 75. Sort Colors
    LeetCode 581. Shortest Unsorted Continuous Subarray
    LeetCode 20. Valid Parentheses
    LeetCode 53. Maximum Subarray
    LeetCode 461. Hamming Distance
    LeetCode 448. Find All Numbers Disappeared in an Array
    LeetCode 976. Largest Perimeter Triangle
    LeetCode 1295. Find Numbers with Even Number of Digits
    如何自学并且系统学习计算机网络?(知乎问答)
  • 原文地址:https://www.cnblogs.com/yaoliang11/p/1804359.html
Copyright © 2011-2022 走看看