一个简单Tracer类,用来为应用写入跟踪

一个简单Tracer类,用来为应用写入跟踪,第1张

一个简单Tracer类,用来为应用写入跟踪,第2张

= = = = = = = = = = = = = =类的代码= = = = = = = = = = = =
{ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * {[/Br/]{ Copyright(C)2004 nil }[/Br/]{ }[/Br/]{ 2004年6月10日}[/Br/]{ * * * * * * * * * * * * * * * * Br/]{[/Br/]通常,TTracer的实例存储在应用程序级别的会话中。 使用时,
创建一个itracenfo,调用tTracer即可。Write (itracenfo),
}
unitcom . sunset . app . tracer;
接口
使用StrUtils、类、SysUtils
type
/= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
itracenfo = interface
functiontostring:string;
end;
//输出目标的接口
I output = interface
过程write(consta info:itraceinfo);//写跟踪信息
end;
//= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
//跟踪信息类,实现itracenfo
/= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
//字符串形式。
public
构造函数Create(data:string);
function to string:string;
end;
//= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
TFILOG = class(
public
const FileName:string);
过程编写(const aInfo:ITraceInfo);//写跟踪信息
end;
TProcStr =对象的过程(常数值:字符串);
TDatabaseLog = class(TInterfacedObject,iout put)
private
FWriteProc:TProcStr;
public
构造函数Create(write proc:TProcStr);
过程编写(const aInfo:ITraceInfo);//写跟踪信息
end;[/Br/]//= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =[/Br/]/跟踪工具[/br/ Br/] //用于记录和跟踪日志的类[/Br/]tTracer = Class(to object)[/Br/]private[/Br/]f output:I output;//output target
过程集输出(const value:I output);
公共
构造函数Create超载;
构造函数Create(aooutput:iout put);超载;
析构函数Destroy覆盖;
属性输出:iout put read fout put write set Output;
过程编写(const aInfo:ITraceInfo);//写跟踪信息
end;
实现
{ TTracer }
构造函数TTracer。创建;
begin
end;
构造函数TTracer。create(aooutput:iout put);
begin
fout put:= aOutput;
end;
析构函数TTracer。破坏;
begin
if fout put nil then fout put:= nil;
继承的;
end;
过程跟踪程序。SetOutput(常数值:iout put);
begin
fout put:= Value;
end;过程跟踪。write(const aInfo:ITraceInfo);
begin
if f output = nilthenraiseeexception . create fmt('无输出目标%s!!!', []);
输出。写(aInfo);
end;
{ TStringTI }
构造函数TStringTI。Create(数据:字符串);
begin
FData:= Data;
end;
函数TStringTI。ToString:字符串;
begin
Result:= FData;
end;
{ TStringLog }
构造函数TFileLog。Create(常量文件名:字符串);
begin
flog file:= FileName;
end;
过程TFileLog。write(const aInfo:ITraceInfo);
begin
if not file exists(flog file)then file close(file create(flog file));
with TStringList。create do
begin
try
LoadFromFile(flog file);
添加(aInfo。ToString);
SaveToFile(flog file);
终于
自由了;
end;
end;
end;
{ TDatabaseLog }
构造函数TDatabaseLog。create(write proc:TProcStr);
begin
FWriteProc:= write proc;
如果未赋值(fwrite proc ),则引发异常。createfmt('没有正确的写入跟踪方法%s!!!', []);
end;
过程TDatabaseLog。write(const aInfo:ITraceInfo);
begin
FWriteProc(aInfo。ToString);
end;
结束。
= = = = = = = = =测试代码= = = = = = = = = = = = = = = = =
{ * * * * * * * * * * * * *

位律师回复
DABAN RP主题是一个优秀的主题,极致后台体验,无插件,集成会员系统
白度搜_经验知识百科全书 » 一个简单Tracer类,用来为应用写入跟踪

0条评论

发表评论

提供最优质的资源集合

立即查看 了解详情