Mark van Renswoude
ca47ad3f4e
Fixed: DateTime is now passed around everywhere (to accomodate the Export functionality)
88 lines
2.0 KiB
ObjectPascal
88 lines
2.0 KiB
ObjectPascal
unit X2Log.Client.Base;
|
|
|
|
interface
|
|
uses
|
|
System.Classes,
|
|
System.Generics.Collections,
|
|
|
|
X2Log.Intf;
|
|
|
|
|
|
type
|
|
TX2LogBaseClient = class(TInterfacedObject, IX2LogBase, IX2LogObservable)
|
|
private
|
|
FObservers: TList<IX2LogObserver>;
|
|
protected
|
|
property Observers: TList<IX2LogObserver> read FObservers;
|
|
public
|
|
constructor Create;
|
|
destructor Destroy; override;
|
|
|
|
{ IX2LogBase }
|
|
procedure Log(ALevel: TX2LogLevel; const AMessage: string; ADetails: IX2LogDetails = nil); overload; virtual;
|
|
procedure Log(ALevel: TX2LogLevel; ADateTime: TDateTime; const AMessage: string; ADetails: IX2LogDetails = nil); overload; virtual;
|
|
|
|
{ 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;
|
|
|
|
|
|
procedure TX2LogBaseClient.Log(ALevel: TX2LogLevel; const AMessage: string; ADetails: IX2LogDetails);
|
|
var
|
|
observer: IX2LogObserver;
|
|
|
|
begin
|
|
for observer in Observers do
|
|
observer.Log(ALevel, AMessage, ADetails);
|
|
end;
|
|
|
|
|
|
procedure TX2LogBaseClient.Log(ALevel: TX2LogLevel; ADateTime: TDateTime; const AMessage: string; ADetails: IX2LogDetails);
|
|
var
|
|
observer: IX2LogObserver;
|
|
|
|
begin
|
|
for observer in Observers do
|
|
observer.Log(ALevel, ADateTime, AMessage, ADetails);
|
|
end;
|
|
|
|
end.
|
|
|