1
0
mirror of synced 2024-11-08 22:29:16 +00:00
x2log/X2Log.Observer.Event.pas

69 lines
1.7 KiB
ObjectPascal
Raw Normal View History

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