一個簡單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;
結束。
= = = = = = = = =測試代碼= = = = = = = = = = = = = = = = =
{ * * * * * * * * * * * * *

位律師廻複

生活常識_百科知識_各類知識大全»一個簡單Tracer類,用來爲應用寫入跟蹤

0條評論

    發表評論

    提供最優質的資源集郃

    立即查看了解詳情