2014-05-25 14:20:58 +00:00
|
|
|
unit X2Log.Client.Base;
|
|
|
|
|
|
|
|
interface
|
|
|
|
uses
|
|
|
|
System.Classes,
|
|
|
|
System.Generics.Collections,
|
|
|
|
|
|
|
|
X2Log.Intf;
|
|
|
|
|
|
|
|
|
|
|
|
type
|
2014-05-30 13:06:47 +00:00
|
|
|
TX2LogBaseClient = class(TInterfacedObject, IX2LogBase, IX2LogObservable)
|
2014-05-25 14:20:58 +00:00
|
|
|
private
|
|
|
|
FObservers: TList<IX2LogObserver>;
|
|
|
|
protected
|
|
|
|
property Observers: TList<IX2LogObserver> read FObservers;
|
|
|
|
public
|
|
|
|
constructor Create;
|
|
|
|
destructor Destroy; override;
|
|
|
|
|
|
|
|
{ IX2LogBase }
|
2014-10-20 12:07:44 +00:00
|
|
|
procedure Log(ALevel: TX2LogLevel; const AMessage: string; const ACategory: string = ''; ADetails: IX2LogDetails = nil); overload; virtual;
|
|
|
|
procedure Log(ALevel: TX2LogLevel; ADateTime: TDateTime; const AMessage: string; const ACategory: string = ''; ADetails: IX2LogDetails = nil); overload; virtual;
|
2014-05-25 14:20:58 +00:00
|
|
|
|
|
|
|
{ IX2LogObservable }
|
|
|
|
procedure Attach(AObserver: IX2LogObserver);
|
|
|
|
procedure Detach(AObserver: IX2LogObserver);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
uses
|
|
|
|
System.SysUtils;
|
|
|
|
|
|
|
|
|
|
|
|
{ TX2LogBaseClient }
|
|
|
|
constructor TX2LogBaseClient.Create;
|
|
|
|
begin
|
|
|
|
inherited Create;
|
|
|
|
|
|
|
|
FObservers := TList<IX2LogObserver>.Create;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
destructor TX2LogBaseClient.Destroy;
|
|
|
|
begin
|
|
|
|
FreeAndNil(FObservers);
|
|
|
|
|
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2LogBaseClient.Attach(AObserver: IX2LogObserver);
|
|
|
|
begin
|
|
|
|
{ Explicit cast ensures we're getting the same pointer in Attach and Detach
|
|
|
|
if, for example, the implementing interface is a descendant of IX2LogObserver }
|
|
|
|
Observers.Add(AObserver as IX2LogObserver);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2LogBaseClient.Detach(AObserver: IX2LogObserver);
|
|
|
|
begin
|
|
|
|
Observers.Remove(AObserver as IX2LogObserver);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-10-20 12:07:44 +00:00
|
|
|
procedure TX2LogBaseClient.Log(ALevel: TX2LogLevel; const AMessage, ACategory: string; ADetails: IX2LogDetails);
|
2014-05-25 14:20:58 +00:00
|
|
|
var
|
|
|
|
observer: IX2LogObserver;
|
|
|
|
|
|
|
|
begin
|
|
|
|
for observer in Observers do
|
2014-10-20 12:07:44 +00:00
|
|
|
observer.Log(ALevel, AMessage, ACategory, ADetails);
|
2014-05-25 14:20:58 +00:00
|
|
|
end;
|
|
|
|
|
2014-10-08 12:33:11 +00:00
|
|
|
|
2014-10-20 12:07:44 +00:00
|
|
|
procedure TX2LogBaseClient.Log(ALevel: TX2LogLevel; ADateTime: TDateTime; const AMessage, ACategory: string; ADetails: IX2LogDetails);
|
2014-10-08 12:33:11 +00:00
|
|
|
var
|
|
|
|
observer: IX2LogObserver;
|
|
|
|
|
|
|
|
begin
|
|
|
|
for observer in Observers do
|
2014-10-20 12:07:44 +00:00
|
|
|
observer.Log(ALevel, ADateTime, AMessage, ACategory, ADetails);
|
2014-10-08 12:33:11 +00:00
|
|
|
end;
|
|
|
|
|
2014-05-25 14:20:58 +00:00
|
|
|
end.
|
|
|
|
|