使用独白和高呼

问题描述 投票:0回答:1

[我试图在set_exception_handlerset_error_handler中使用Monolog,而外面却鸣叫。

我尝试了2个位置来运行Whoops。

  1. Run Whoops #1 Location
    • 结果:Monolog记录错误/异常,并且不显示Whoops
  2. Run Whoops #2 Location
    • 结果:Monolog不记录任何内容,并且显示Whoops

我坚持为什么我无法同时使Monolog和Whoops一起工作。

...
use Whoops\Run;
use Whoops\Handler\PrettyPageHandler;

error_reporting(E_ALL);
ini_set('display_errors', 1);
//Run Whoops #1 Location
$whoops = new Run();
$whoops->prependHandler(new PrettyPageHandler());
$whoops->register();

function exceptionHandler($e)
{ 
    //log the exception using monolog
}

function errorHandler($errno, $errstr, $errfile, $errline)
{
    //log the error using monolog
}

set_error_handler("errorHandler");
set_exception_handler('exceptionHandler');

//Run Whoops #2 Location
php exception monolog whoops
1个回答
0
投票
php中的

函数被Whoops库覆盖。我们可以使用Whoops库的pushHandler方法注册一个通用处理函数,并在该函数内部初始化Monolog:

$whoops = new \Whoops\Run; $whoops->pushHandler(function($exception, $inspector, $run) { // Initialise Monolog here });
© www.soinside.com 2019 - 2024. All rights reserved.