irap / exception-logger
Package for capturing and logging uncaught exceptions.
Installs: 1 054
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: >=7.0.0
- irap/logging: 2.0.*
Requires (Dev)
- irap/autoloader: ^1.0
This package is auto-updated.
Last update: 2024-11-12 12:46:22 UTC
README
A package to capture uncaught exceptions and log them using the provided logger. All you have to do is create the object like so:
new \iRAP\ExceptionLogger\ExceptionLogger( $logger, // objec tof LoggerInterface "My Service", $nextExcptionHandler=function(Throwable $e) { /* do nothing */ } );
This will result in any uncaught exceptions being logged. The object works by setting the exception handler so it won't have any effect if you call set_exception_handler after having created the object.
If you want to run your own exception handler, you can just have it be called by the callback as shown below:
/* @var $logger LoggerInterface */ $nextExcptionHandler = function(Throwable $e) { // my custom uncaught exception handling goes here. }; new \iRAP\ExceptionLogger\ExceptionLogger( $logger, "My Service", nextExcptionHandler );
If you don't have a custom exception handler, I would recommend restoring PHP's default exception handling by doing the following:
$next = function(Throwable $e) { restore_exception_handler(); throw $e; //This triggers the previous exception handler }; new \iRAP\ExceptionLogger\ExceptionLogger( $logger, "My Service", $next );