forked from zamronypj/fano
/
ProductionErrorHandlerFactoryImpl.pas
65 lines (52 loc) · 1.69 KB
/
ProductionErrorHandlerFactoryImpl.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
{*!
* Fano Web Framework (https://fanoframework.github.io)
*
* @link https://github.com/fanoframework/fano
* @copyright Copyright (c) 2018 Zamrony P. Juhara
* @license https://github.com/fanoframework/fano/blob/master/LICENSE (MIT)
*}
unit ProductionErrorHandlerFactoryImpl;
interface
{$MODE OBJFPC}
uses
DependencyIntf,
DependencyContainerIntf,
FactoryImpl;
type
(*!------------------------------------------------
* factory class for error handler for production setup
* which is to log exception to file and output
* nicely formatted error page
*
* @author Zamrony P. Juhara <zamronypj@yahoo.com>
*-------------------------------------------------*)
TProductionErrorHandlerFactory = class(TFactory, IDependencyFactory)
private
logFilename : string;
templateFilename : string;
public
constructor create(const logFile : string; const templateFile : string);
function build(const container : IDependencyContainer) : IDependency; override;
end;
implementation
uses
FileLoggerImpl,
TemplateErrorHandlerImpl,
CompositeErrorHandlerImpl,
LogErrorHandlerImpl;
constructor TProductionErrorHandlerFactory.create(
const logFile : string;
const templateFile : string
);
begin
logFilename := logFile;
templateFilename := templateFile;
end;
function TProductionErrorHandlerFactory.build(const container : IDependencyContainer) : IDependency;
begin
result := TCompositeErrorHandler.create(
TLogErrorHandler.create(TFileLogger.create(logFilename)),
TTemplateErrorHandler.create(templateFilename)
)
end;
end.