我有一个ZF 3应用程序。我明确记录的信息例如$log->debug()
显示得很好。例外情况不。错误似乎显示,因为这是默认的PHP配置去标准错误。下面是从modules.config.php相关线路:我是否正确配置Zend-Log的错误处理程序和异常管理器?
'service_manager' => [
'factories' => [
. . . .
'log' => \Zend\Log\LoggerServiceFactory::class,
],
],
'log' => [
'writers' => [
[
'name' => 'stream',
'options' => [ 'stream' => 'php://stderr' ]
],
],
'errorHandler' => true,
'exceptionhandler' => true,
],
The lines in the source that lead me to believe this is the correct config。
if (isset($options['exceptionhandler']) && $options['exceptionhandler'] === true) {
static::registerExceptionHandler($this);
}
if (isset($options['errorhandler']) && $options['errorhandler'] === true) {
static::registerErrorHandler($this);
}
为了测试它,我做了如下endpouints:
public function errorAction()
{
$msg = $this->params()->fromQuery('msg', 'Default Error message');
trigger_error('Index Error Action' . $msg, E_USER_ERROR);
$model = new JsonErrorModel(['msg' => $msg]);
return $model;
}
public function exceptionAction()
{
$msg = $this->params()->fromQuery('msg', 'Default Error message');
throw new \RuntimeException('Index Exception Action' . $msg);
$model = new JsonErrorModel(['msg' => $msg]);
return $model;
}
我修正了这个问题,并添加了致命的错误记录。我仍然看不到日志中的th th声。我编辑了我的示例端点不起作用的问题。例外情况未处理。 –
我编辑了我的答案..你只是没有初始化记录器。在配置文件中注册服务/模型,但Zend在第一次调用这个服务之后从它创建类。 – SzymonM
谢谢。那样做了! –