dotkernel / dot-errorhandler

Logging Error Handler for DotKernel
https://docs.dotkernel.org/dot-errorhandler/
MIT License
5 stars 1 forks source link
dotkernel error-handler

dot-errorhandler

Error Logging Handler for DotKernel

OSS Lifecycle PHP from Packagist (specify version)

GitHub issues GitHub forks GitHub stars GitHub license

Build Static codecov

SymfonyInsight

Adding the error handler

composer require dotkernel/dot-errorhandler

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 declaring the ErrorHandlerInterface alias you can choose whether to log or not:

The class Dot\ErrorHandler\ErrorHandler is the same as the Zend Expressive error handling class the only difference being the removal of the final statement for making extension possible.

The class Dot\ErrorHandler\LogErrorHandler is Dot\ErrorHandler\ErrorHandler with added logging support.

As a note: both LogErrorHandler and ErrorHandler have factories declared in the package's ConfigProvider. If you need a custom ErrorHandler it must have a factory declared in the config, as in the example.

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.