Skip to content
  • Sponsor
  • Notifications You must be signed in to change notification settings
  • Fork 4

Commit 3e7c2b4

Browse files
committedNov 27, 2021
improve logger error handler
1 parent a39d1e5 commit 3e7c2b4

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed
 

‎error-handler/index.md

+18-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Fano Framework comes with several `IErrorHandler` implementation.
6767
- `TNullErrorHandler`, error handler that output nothing except HTTP error.
6868
- `THtmlAjaxErrorHandler`, composite error handler that output basic HTML error or JSON based on whether request is AJAX or not.
6969
- `TLogErrorHandler`, error handler that log error information instead of output it to client.
70+
- `TLoggerErrorHandler`, error handler that similar to `TLogErrorHandler` except it can determine what log level to be log. For example it can log critical type log only.
7071
- `TTemplateErrorHandler`, error handler that output error using HTML template. This class is provided to enable developer to display nicely formatted error page. For production setup, this is mostly what you use.
7172
- `TCompositeErrorHandler` error handler that is composed from two other error handler. This is provided so we combine, for example, log error to file and also displaying nicely formatted output to client. To combine three or more error handlers, you need to daisy-chain them.
7273
- `TGroupErrorHandler` error handler that is composed from one or more error handlers. This is similar to composite error handler above, except, it is more flexible as you can compose arbitrary number of error handlers.
@@ -159,7 +160,23 @@ begin
159160
end;
160161
```
161162

162-
You need to make sure that `/path/to/log/file` is writeable. Read [Using Logger documentation](/utilities/using-loggers) for more information on how to use logger utility.
163+
You need to make sure that `/path/to/log/file` is writeable.
164+
165+
Or if you want to log emergency and critical message only, use `TLoggerErrorHandler` instead.
166+
```
167+
function TAppServiceProvider.buildErrorHandler(
168+
const ctnr : IDependencyContainer;
169+
const config : IAppConfiguration
170+
) : IErrorHandler;
171+
begin
172+
result := TLoggerErrorHandler.create(
173+
TFileLogger.create('/path/to/log/file'),
174+
[ logEmergency, logCritical ]
175+
);
176+
end;
177+
```
178+
179+
Read [Using Logger documentation](/utilities/using-loggers) for more information on how to use logger utility.
163180

164181
## Log error to file and display error from template
165182

0 commit comments

Comments
 (0)