forked from danieleteti/loggerpro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoggerPro.Proxy.pas
74 lines (57 loc) · 1.86 KB
/
LoggerPro.Proxy.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
unit LoggerPro.Proxy;
interface
uses Classes, System.SysUtils, LoggerPro;
type
ILogAppenderProxy=interface
['{34816F83-9FBF-461E-8913-F10F9460D712}']
function GetInternalAppender: ILogAppender;
property InternalAppender: ILogAppender read GetInternalAppender;
end;
TLoggerProFilter = class abstract
class function Build(Appender: ILogAppender; Filter: TFunc<TLogItem, boolean>): ILogAppender;
end;
implementation
type
TLoggerProAppenderFilterImpl = class(TLoggerProAppenderBase, ILogAppender, ILogAppenderProxy)
private
FAppender: ILogAppender;
FFilter: TFunc<TLogItem, boolean>;
function GetInternalAppender: ILogAppender;
public
procedure Setup; override;
procedure TearDown; override;
procedure WriteLog(const aLogItem: TLogItem); override;
property InternalAppender: ILogAppender read GetInternalAppender;
constructor Create(Appender: ILogAppender; Filter: TFunc<TLogItem, boolean>); reintroduce;
end;
{ TLoggerProAppenderFilterImpl }
constructor TLoggerProAppenderFilterImpl.Create(Appender: ILogAppender;
Filter: TFunc<TLogItem, boolean>);
begin
inherited Create;
self.FFilter := Filter;
self.FAppender := Appender;
end;
function TLoggerProAppenderFilterImpl.GetInternalAppender: ILogAppender;
begin
result := FAppender;
end;
procedure TLoggerProAppenderFilterImpl.Setup;
begin
FAppender.Setup;
end;
procedure TLoggerProAppenderFilterImpl.TearDown;
begin
FAppender.TearDown;
end;
procedure TLoggerProAppenderFilterImpl.WriteLog(const aLogItem: TLogItem);
begin
if FFilter(aLogItem) then
FAppender.WriteLog(aLogItem);
end;
class function TLoggerProFilter.Build(Appender: ILogAppender;
Filter: TFunc<TLogItem, boolean>): ILogAppender;
begin
result := TLoggerProAppenderFilterImpl.Create(Appender, Filter);
end;
end.