irap / exception-logger
捕获并记录未捕获异常的包。
1.1.2
2022-10-12 08:01 UTC
Requires
- php: >=7.0.0
- irap/logging: 2.0.*
Requires (Dev)
- irap/autoloader: ^1.0
This package is auto-updated.
Last update: 2024-09-12 12:23:35 UTC
README
一个用于捕获未捕获异常并通过提供的记录器记录它们的包。您只需创建对象,如下所示
new \iRAP\ExceptionLogger\ExceptionLogger( $logger, // objec tof LoggerInterface "My Service", $nextExcptionHandler=function(Throwable $e) { /* do nothing */ } );
这将导致任何未捕获的异常被记录。该对象通过设置异常处理器来工作,如果您在创建对象后调用 set_exception_handler,则它将没有任何效果。
如果您想运行自己的异常处理器,可以让它像下面这样通过回调被调用
/* @var $logger LoggerInterface */ $nextExcptionHandler = function(Throwable $e) { // my custom uncaught exception handling goes here. }; new \iRAP\ExceptionLogger\ExceptionLogger( $logger, "My Service", nextExcptionHandler );
如果您没有自定义异常处理器,我建议您通过以下方式恢复PHP的默认异常处理
$next = function(Throwable $e) { restore_exception_handler(); throw $e; //This triggers the previous exception handler }; new \iRAP\ExceptionLogger\ExceptionLogger( $logger, "My Service", $next );