dotkernel / dot-errorhandler
Logging Error Handler for Middleware Applications
Installs: 32 099
Dependents: 5
Suggesters: 0
Security: 0
Stars: 5
Watchers: 4
Forks: 2
Open Issues: 2
pkg:composer/dotkernel/dot-errorhandler
Requires
- php: ~8.2.0 || ~8.3.0 || ~8.4.0
- dotkernel/dot-log: ^5.0
- laminas/laminas-diactoros: ^3.5
- laminas/laminas-stdlib: ^3.20
- laminas/laminas-stratigility: ^3.13
- mezzio/mezzio: ^3.20.1
- psr/http-message: ^1.0 || ^2.0
- psr/http-server-middleware: ^1.0.2
Requires (Dev)
- laminas/laminas-coding-standard: ^3.0.1
- mikey179/vfsstream: ^1.6.12
- phpstan/phpstan: ^2.1
- phpstan/phpstan-phpunit: ^2.0
- phpunit/phpunit: ^10.5.45
README
dot-errorhandler is Dotkernel's PSR-15 compliant error handler.
Documentation
Documentation is available at: https://docs.dotkernel.org/dot-errorhandler/
Badges
Adding the error handler
- Add the composer package:
composer require dotkernel/dot-errorhandler
- Add the config provider:
- in
config/config.php
add\Dot\ErrorHandler\ConfigProvider
- in
config/pipeline.php
add\Dot\ErrorHandler\ErrorHandlerInterface::class
- the interface is used as an alias to keep all error handling related configurations in one file
- in
If you need other error handlers, you should place them before dot-errorhandler in the pipeline; else it will not be able to catch errors. We recommend using just one error handler unless you have an error-specific handler.
- Configure the error handler as shown below.
In config/autoload/error-handling.global.php
:
<?php use Dot\ErrorHandler\ErrorHandlerInterface; use Dot\ErrorHandler\LogErrorHandler; use Dot\ErrorHandler\ErrorHandler; return [ 'dependencies' => [ 'aliases' => [ ErrorHandlerInterface::class => LogErrorHandler::class, ] ], 'dot-errorhandler' => [ 'loggerEnabled' => true, 'logger' => 'dot-log.default_logger' ] ];
A configuration example for the default logger can be found in config/log.global.php.dist
.
When configuring the error handler in your application, you can choose between two classes:
Dot\ErrorHandler\LogErrorHandler
: for logging and displaying errorsDot\ErrorHandler\ErrorHandler
: for displaying errors only
Both
LogErrorHandler
andErrorHandler
have factories declared in the package'sConfigProvider
. If you need a custom ErrorHandler, it must have a factory declared in the config, as in the below example:
<?php use Dot\ErrorHandler\ErrorHandlerInterface; use Custom\MyErrorHandler; use Custom\MyErrorHandlerFactory; return [ 'dependencies' => [ 'factories' => [ MyErrorHandler::class => MyCustomHandlerFactory::class, ], 'aliases' => [ ErrorHandlerInterface::class => MyErrorHandler::class, ] ], 'dot-errorhandler' => [ 'loggerEnabled' => true, 'logger' => 'dot-log.default_logger', ] ];
Config examples can be found in this project's config
directory.