[FMX] 使用日志调试跟踪程序 – QDAC数据访问组件网站 您所在的位置:网站首页 超市卖粮食区买的的大麦能做大麦茶吗安全吗 [FMX] 使用日志调试跟踪程序 – QDAC数据访问组件网站

[FMX] 使用日志调试跟踪程序 – QDAC数据访问组件网站

2024-04-22 23:50| 来源: 网络整理| 查看: 265

可能许多人象我一样没有注意到,FMX.Types 提供了一个调试日志的管理类,用来在程序中输出日志。

Windows 下,日志被使用 OutputDebugString 一样,输出到调试器的 Event Log 里 Android 下,日志被输出给LogCat,你可以用Android 平台 SDK 的tools 目录下的 monitor.bat 来打开 Android Device Monitor 工具来查看日志。AndroidDeviceMonitor

如果没有特殊指定,monitor.bat 应该位于 C:\Users\Public\Documents\Embarcadero\Studio\16.0\PlatformSDKs\android-sdk-windows\tools 目录下。

iOS 需要到 xcode 的 Organizer 里的Console 查看日志,请参考:http://www.th7.cn/Program/IOS/2012/03/09/62910.shtml OSX 好象需要到控制台去查看日志。

osxlog

在程序中,记录日志实际上在引用 FMX.Types 后,就很简单了,只需要一句话:

procedure TForm3.FormCreate(Sender: TObject); begin Log.d('Hello,world'); end;

当然,它还有几个方法,大家看下声明就一目了然了,俺不就啰嗦凑字数了:

/// Log a debug message. Same arguments as Format. class procedure d(const Fmt: string; const Args: array of const); overload; /// Log a simple debug message. class procedure d(const Msg: string); overload; inline; /// Log a debug message with Tag, object data of Instance, Method that invokes the logger and message Msg. /// class procedure d(const Tag: string; const Instance: TObject; const Method, Msg: string); overload; inline; /// Log a debug message with Tag, object data of Instance and a message Msg class procedure d(const Tag: string; const Instance: TObject; const Msg: string); overload; inline; /// Log a time stamp with message Msg class procedure TimeStamp(const Msg: string); overload; /// Perform a timed execution of Func and print execution times, return function result. /// Proc receives a parameter TLogToken which can be used to mark specific points where timestamps should be taken /// in addition to complete procedure time. class function Trace(const Tag: string; const Func: TFunc; const Threshold: Integer = -1): TResult; overload; /// A convenience variant of Trace when token is not needed. class function Trace(const Tag: string; const Func: TFunc; const Threshold: Integer = -1): TResult; overload; /// A convenience variant of Trace for procedures. class procedure Trace(const Tag: string; const Proc: TProc; const Threshold: Integer = -1); overload; /// A convenience variant of Trace for procedures when token is not needed. class procedure Trace(const Tag: string; const Proc: TProc; const Threshold: Integer = -1); overload; /// Get a basic string representation of an object, consisting of ClassName and its pointer class function ObjToString(const Instance: TObject): string; /// Get a string representation of array using MakeStr function to convert individual elements. class function ArrayToString(const AArray: TEnumerable; const MakeStr: TToStringFunc): string; overload; /// Get a string representation of array using TObject.ToString to convert individual elements. class function ArrayToString(const AArray: TEnumerable): string; overload; /// Dump complete TFmxObject with all its children. class procedure DumpFmxObject(const AObject: TFmxObject; const Nest: Integer = 0);

实际上,在 VCL 程序下,你也可以引用 FMX.Types 单元,然后再调用 Log.d 函数来记录日志。

最后,个人建议您使用 QLog 记录日志,简单易用跨平台,而且日志可以还支持 SyslogD 协议,日志的输出途径多样,文件、控制台、SyslogD 兼容的远程日志服务器都可以,文件日志支持自动分卷压缩,还可以自行实现更多的 TQLogWriter。



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有