2014-05-18 18:09:07 +00:00
|
|
|
unit X2Log.Observer.Event;
|
|
|
|
|
|
|
|
interface
|
|
|
|
uses
|
|
|
|
X2Log.Intf,
|
|
|
|
X2Log.Observer.Custom;
|
|
|
|
|
|
|
|
|
|
|
|
type
|
2014-10-20 12:07:44 +00:00
|
|
|
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;
|
2014-05-25 14:20:58 +00:00
|
|
|
FRunInMainThread: Boolean;
|
2014-05-18 18:09:07 +00:00
|
|
|
protected
|
2014-10-20 12:07:44 +00:00
|
|
|
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;
|
|
|
|
|
2014-05-25 14:20:58 +00:00
|
|
|
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
|
2014-05-25 14:20:58 +00:00
|
|
|
uses
|
|
|
|
System.Classes;
|
2014-05-18 18:09:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
{ TX2LogEventObserver }
|
|
|
|
constructor TX2LogEventObserver.Create(ALogLevels: TX2LogLevels);
|
|
|
|
begin
|
|
|
|
inherited Create(ALogLevels);
|
2014-05-25 14:20:58 +00:00
|
|
|
|
|
|
|
FRunInMainThread := True;
|
2014-05-18 18:09:07 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
constructor TX2LogEventObserver.Create(AOnLog: TX2LogEvent; ALogLevels: TX2LogLevels);
|
|
|
|
begin
|
|
|
|
Create(ALogLevels);
|
|
|
|
|
|
|
|
FOnLog := AOnLog;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-10-20 12:07:44 +00:00
|
|
|
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
|
2014-05-25 14:20:58 +00:00
|
|
|
begin
|
|
|
|
if RunInMainThread then
|
|
|
|
begin
|
|
|
|
TThread.Queue(nil,
|
|
|
|
procedure
|
|
|
|
begin
|
|
|
|
if Assigned(FOnLog) then
|
2014-10-20 12:07:44 +00:00
|
|
|
FOnLog(Self, ALevel, ADateTime, AMessage, ACategory, ADetails);
|
2014-05-25 14:20:58 +00:00
|
|
|
end);
|
|
|
|
end else
|
2014-10-20 12:07:44 +00:00
|
|
|
FOnLog(Self, ALevel, ADateTime, AMessage, ACategory, ADetails);
|
2014-05-25 14:20:58 +00:00
|
|
|
end;
|
2014-05-18 18:09:07 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|