1
0
mirror of synced 2024-11-12 15:49:16 +00:00
x2log/X2Log.Observer.Event.pas
Mark van Renswoude 6d5355e0b6 Added: support for binary details
Added: Save button for Monitor Form
2014-05-30 12:51:01 +00:00

69 lines
1.6 KiB
ObjectPascal

unit X2Log.Observer.Event;
interface
uses
X2Log.Intf,
X2Log.Observer.Custom;
type
TX2LogEvent = procedure(Sender: TObject; Level: TX2LogLevel; const Msg: string; Details: IX2LogDetails) of object;
TX2LogEventObserver = class(TX2LogCustomObserver)
private
FOnLog: TX2LogEvent;
FRunInMainThread: Boolean;
protected
procedure DoLog(ALevel: TX2LogLevel; const AMessage: string; ADetails: IX2LogDetails); override;
public
constructor Create(ALogLevels: TX2LogLevels = X2LogLevelsDefault); overload;
constructor Create(AOnLog: TX2LogEvent; ALogLevels: TX2LogLevels = X2LogLevelsDefault); overload;
property RunInMainThread: Boolean read FRunInMainThread write FRunInMainThread default True;
property OnLog: TX2LogEvent read FOnLog write FOnLog;
end;
implementation
uses
System.Classes;
{ TX2LogEventObserver }
constructor TX2LogEventObserver.Create(ALogLevels: TX2LogLevels);
begin
inherited Create(ALogLevels);
FRunInMainThread := True;
end;
constructor TX2LogEventObserver.Create(AOnLog: TX2LogEvent; ALogLevels: TX2LogLevels);
begin
Create(ALogLevels);
FOnLog := AOnLog;
end;
procedure TX2LogEventObserver.DoLog(ALevel: TX2LogLevel; const AMessage: string; ADetails: IX2LogDetails);
begin
if Assigned(FOnLog) then
begin
if RunInMainThread then
begin
TThread.Queue(nil,
procedure
begin
if Assigned(FOnLog) then
FOnLog(Self, ALevel, AMessage, ADetails);
end);
end else
FOnLog(Self, ALevel, AMessage, ADetails);
end;
end;
end.