-
Notifications
You must be signed in to change notification settings - Fork 1
/
Logger.AbstractLogger.pp
170 lines (145 loc) · 5.31 KB
/
Logger.AbstractLogger.pp
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
{*******************************************************}
{ Renegade BBS }
{ Copyright (c) 1990-2013 The Renegade Dev Team }
{ Copyleft (ↄ) 2016-2017 Renegade BBS }
{ This file is part of Renegade BBS }
{ Renegade is free software: you can redistribute it }
{ and/or modify it under the terms of the GNU General }
{ Public License as published by the Free Software }
{ Foundation, either version 3 of the License, or }
{ (at your option) any later version. }
{ Renegade is distributed in the hope that it will be }
{ useful, but WITHOUT ANY WARRANTY; without even the }
{ implied warranty of MERCHANTABILITY or FITNESS FOR }
{ A PARTICULAR PURPOSE. See the GNU General Public }
{ License for more details. }
{ You should have received a copy of the GNU General }
{ Public License along with Renegade. If not, see }
{ <http://www.gnu.org/licenses/>. }
{*******************************************************}
{ _______ __ }
{ | _ .-----.-----.-----.-----.---.-.--| .-----. }
{ |. l | -__| | -__| _ | _ | _ | -__| }
{ |. _ |_____|__|__|_____|___ |___._|_____|_____| }
{ |: | | |_____| }
{ |::.|:. | }
{ `--- ---' }
{*******************************************************}
{$mode objfpc}
{$codepage utf8}
{$h+}
{ namespace Renegade.Logger }
{ Abstract Logger Class }
{
If you don't need any custom code for the procedures Emergency to Debug
you can extend this class and only implement the Log procedure.
}
unit Logger.AbstractLogger;
interface
uses
Classes,
SysUtils,
Math,
Logger.LoggerInterface,
Logger.HandlerInterface,
Logger.SysLogHandler;
type
AbstractLogger = class abstract(TObject, LoggerInterface)
private
FLoggingHandler: LoggingHandlerInterface;
procedure SetHandler(LoggingHandler: LoggingHandlerInterface);
public
constructor Create(LoggingHandler: LoggingHandlerInterface);
destructor Destroy; override;
procedure Emergency(Message: UTF8String; Context: array of const);
procedure Alert(Message: UTF8String; Context: array of const);
procedure Critical(Message: UTF8String; Context: array of const);
procedure Error(Message: UTF8String; Context: array of const);
procedure Warning(Message: UTF8String; Context: array of const);
procedure Notice(Message: UTF8String; Context: array of const);
procedure Info(Message: UTF8String; Context: array of const);
procedure Debug(Message: UTF8String; Context: array of const);
function ConvertLogErrorToString(LogLevel: LogLevels): ansistring;
function ConvertLogStringToError( LogString : AnsiString): LogLevels;
procedure Log(LogLevel: LogLevels; Message: UTF8String;
Context: array of const); virtual; abstract;
published
property LoggingHandler: LoggingHandlerInterface
read FLoggingHandler write SetHandler;
end;
implementation
function AbstractLogger.ConvertLogErrorToString(LogLevel: LogLevels): ansistring;
begin
case LogLevel of
LOG_EMERG: Result := 'Emergency';
LOG_ALERT: Result := 'Alert';
LOG_CRIT: Result := 'Critical';
LOG_ERR: Result := 'Error';
LOG_WARNING: Result := 'Warning';
LOG_NOTICE: Result := 'Notice';
LOG_INFO: Result := 'Info';
LOG_DEBUG: Result := 'Debug';
else
Result := 'Unknown';
end;
end;
function AbstractLogger.ConvertLogStringToError(LogString : AnsiString) : LogLevels;
begin
case lowerCase(LogString) of
'emergency': Result := LOG_EMERG;
'alert': Result := LOG_ALERT;
'critical': Result := LOG_CRIT;
'error': Result := LOG_ERR;
'warning': Result := LOG_WARNING;
'notice': Result := LOG_NOTICE;
'info': Result := LOG_INFO;
'debug': Result := LOG_DEBUG;
else
Result := LOG_UNKNOWN;
end;
end;
procedure AbstractLogger.SetHandler(LoggingHandler: LoggingHandlerInterface);
begin
FLoggingHandler := LoggingHandler;
end;
constructor AbstractLogger.Create(LoggingHandler: LoggingHandlerInterface);
begin
FLoggingHandler := LoggingHandler;
end;
destructor AbstractLogger.Destroy;
begin
inherited Destroy;
end;
procedure AbstractLogger.Emergency(Message: UTF8String; Context: array of const);
begin
Log(LOG_EMERG, Message, Context);
end;
procedure AbstractLogger.Alert(Message: UTF8String; Context: array of const);
begin
Log(LOG_ALERT, Message, Context);
end;
procedure AbstractLogger.Critical(Message: UTF8String; Context: array of const);
begin
Log(LOG_CRIT, Message, Context);
end;
procedure AbstractLogger.Error(Message: UTF8String; Context: array of const);
begin
Log(LOG_ERR, Message, Context);
end;
procedure AbstractLogger.Warning(Message: UTF8String; Context: array of const);
begin
Log(LOG_WARNING, Message, Context);
end;
procedure AbstractLogger.Notice(Message: UTF8String; Context: array of const);
begin
Log(LOG_NOTICE, Message, Context);
end;
procedure AbstractLogger.Info(Message: UTF8String; Context: array of const);
begin
Log(LOG_INFO, Message, Context);
end;
procedure AbstractLogger.Debug(Message: UTF8String; Context: array of const);
begin
Log(LOG_DEBUG, Message, Context);
end;
end.