刚开始使用Monolog在我的PHP项目中记录错误,但是我想将最小错误报告设置设置为NOTICE或更高。我现在正在使用的代码
use Monolog\ErrorHandler;
$handler = new ErrorHandler($logger);
$handler->registerErrorHandler([], false);
$handler->registerExceptionHandler();
$handler->registerFatalHandler();
生成所有错误,包括通知。如何设置等价于
error_reporting(E_ALL & ~E_NOTICE);
使用Monolog
最佳答案
除非您使用ErrorHandler
运算符将它们静音或通过trigger_error
实际设置error_reporting,否则@
将捕获所有级别的error_reporting(E_ALL & ~E_NOTICE);
。
如果出于某种原因您想保留错误报告,但同时滤除独白错误处理程序捕获的那些错误,则我将扩展错误处理程序并进行注册。像这样:
class MyErrorHandler extends Monolog\ErrorHandler{
public function handleError($code, $message, $file = '', $line = 0, $context = [])
{
if($code === E_NOTICE){
return;
}
parent::handleError($code, $message, $file, $line, $context);
}
}
use MyErrorHandler as ErrorHandler;
$handler = new ErrorHandler($logger);
$handler->registerErrorHandler([], false);
$handler->registerExceptionHandler();
$handler->registerFatalHandler();
请注意,我尚未对此进行实际测试,但是我发现没有任何理由无法正常工作
关于php - 在Monolog ErrorHandler中设置最小的PHP错误报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43665088/