forked from Xor-el/CryptoLib4Pascal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExampleLogger.pas
More file actions
113 lines (82 loc) · 4.24 KB
/
Copy pathExampleLogger.pas
File metadata and controls
113 lines (82 loc) · 4.24 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
{ *********************************************************************************** }
{ * CryptoLib Library * }
{ * Author - Ugochukwu Mmaduekwe * }
{ * Github Repository <https://github.com/Xor-el> * }
{ * * }
{ * Distributed under the MIT software license, see the accompanying file LICENSE * }
{ * or visit http://www.opensource.org/licenses/mit-license.php. * }
{ * * }
{ * Acknowledgements: * }
{ * * }
{ * Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring * }
{ * the development of this library * }
{ * ******************************************************************************* * }
(* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
unit ExampleLogger;
interface
{$IFDEF FPC}
{$MODE DELPHI}
{$HINTS OFF}
{$WARNINGS OFF}
{$ENDIF FPC}
uses
SysUtils;
type
TLogLevel = (Trace, Debug, Info, Warn, Error, Fatal);
TEventId = record
private
FId: Integer;
FName: string;
public
constructor Create(AId: Integer; const AName: string = '');
function IsEmpty: Boolean;
property Id: Integer read FId;
property Name: string read FName;
class function Empty: TEventId; static;
end;
/// ILogger interface
ILogger = interface
['{A5F8F5E2-25B9-4C5A-9E78-AD52E3A7E8D9}']
// Core logging
procedure Log(ALevel: TLogLevel; const EventId: TEventId; const MessageTemplate: string; const Args: array of const); overload;
procedure Log(ALevel: TLogLevel; const MessageTemplate: string; const Args: array of const); overload;
procedure LogException(ALevel: TLogLevel; const EventId: TEventId; const E: Exception; const MessageTemplate: string; const Args: array of const); overload;
procedure LogException(ALevel: TLogLevel; const E: Exception; const MessageTemplate: string; const Args: array of const); overload;
procedure LogTrace(const MessageTemplate: string; const Args: array of const); overload;
procedure LogTrace(const EventId: TEventId; const MessageTemplate: string; const Args: array of const); overload;
procedure LogDebug(const MessageTemplate: string; const Args: array of const); overload;
procedure LogDebug(const EventId: TEventId; const MessageTemplate: string; const Args: array of const); overload;
procedure LogInformation(const MessageTemplate: string; const Args: array of const); overload;
procedure LogInformation(const EventId: TEventId; const MessageTemplate: string; const Args: array of const); overload;
procedure LogWarning(const MessageTemplate: string; const Args: array of const); overload;
procedure LogWarning(const EventId: TEventId; const MessageTemplate: string; const Args: array of const); overload;
procedure LogError(const MessageTemplate: string; const Args: array of const); overload;
procedure LogError(const EventId: TEventId; const MessageTemplate: string; const Args: array of const); overload;
procedure LogCritical(const MessageTemplate: string; const Args: array of const); overload;
procedure LogCritical(const EventId: TEventId; const MessageTemplate: string; const Args: array of const); overload;
function IsEnabled(ALevel: TLogLevel): Boolean;
function Category: string;
end;
/// ILoggerFactory interface
ILoggerFactory = interface
['{34F7A5B1-9D0C-4DD8-8C6D-6B1E9E8A3A0F}']
function CreateLogger(const CategoryName: string): ILogger;
procedure SetMinimumLevel(ALevel: TLogLevel);
function GetMinimumLevel: TLogLevel;
end;
implementation
{ TEventId }
constructor TEventId.Create(AId: Integer; const AName: string);
begin
FId := AId;
FName := AName;
end;
function TEventId.IsEmpty: Boolean;
begin
Result := (FId = 0) and (FName = '');
end;
class function TEventId.Empty: TEventId;
begin
Result := Default(TEventId);
end;
end.