2014-05-18 18:09:07 +00:00
|
|
|
unit X2Log.Observer.Custom;
|
|
|
|
|
|
|
|
interface
|
|
|
|
uses
|
|
|
|
Classes,
|
|
|
|
SysUtils,
|
|
|
|
|
|
|
|
X2Log.Intf;
|
|
|
|
|
|
|
|
|
|
|
|
type
|
|
|
|
TX2LogLevels = set of TX2LogLevel;
|
|
|
|
|
2014-05-30 12:51:01 +00:00
|
|
|
TX2LogCustomObserver = class(TInterfacedObject, IX2LogBase, IX2LogObserver)
|
2014-05-18 18:09:07 +00:00
|
|
|
private
|
|
|
|
FLogLevels: TX2LogLevels;
|
|
|
|
protected
|
2014-10-20 12:07:44 +00:00
|
|
|
procedure DoLog(ALevel: TX2LogLevel; ADateTime: TDateTime; const AMessage, ACategory: string; ADetails: IX2LogDetails); virtual; abstract;
|
2014-05-18 18:09:07 +00:00
|
|
|
|
|
|
|
property LogLevels: TX2LogLevels read FLogLevels;
|
|
|
|
public
|
|
|
|
constructor Create(ALogLevels: TX2LogLevels = X2LogLevelsDefault);
|
2014-05-30 12:51:01 +00:00
|
|
|
|
|
|
|
{ IX2LogBase }
|
2014-10-20 12:07:44 +00:00
|
|
|
procedure Log(ALevel: TX2LogLevel; const AMessage: string; const ACategory: string = ''; ADetails: IX2LogDetails = nil); overload;
|
|
|
|
procedure Log(ALevel: TX2LogLevel; ADateTime: TDateTime; const AMessage: string; const ACategory: string = ''; ADetails: IX2LogDetails = nil); overload;
|
2014-05-18 18:09:07 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
|
|
|
|
{ TX2LogCustomObserver }
|
|
|
|
constructor TX2LogCustomObserver.Create(ALogLevels: TX2LogLevels);
|
|
|
|
begin
|
|
|
|
inherited Create;
|
|
|
|
|
|
|
|
FLogLevels := ALogLevels;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-10-20 12:07:44 +00:00
|
|
|
procedure TX2LogCustomObserver.Log(ALevel: TX2LogLevel; const AMessage, ACategory: string; ADetails: IX2LogDetails);
|
2014-10-08 12:33:11 +00:00
|
|
|
begin
|
2014-10-20 12:07:44 +00:00
|
|
|
Log(ALevel, Now, AMessage, ACategory, ADetails);
|
2014-10-08 12:33:11 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-10-20 12:07:44 +00:00
|
|
|
procedure TX2LogCustomObserver.Log(ALevel: TX2LogLevel; ADateTime: TDateTime; const AMessage, ACategory: string; ADetails: IX2LogDetails);
|
2014-05-18 18:09:07 +00:00
|
|
|
begin
|
|
|
|
if ALevel in LogLevels then
|
2014-10-20 12:07:44 +00:00
|
|
|
DoLog(ALevel, ADateTime, AMessage, ACategory, ADetails);
|
2014-05-18 18:09:07 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|
|
|
|
|