我有一個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
謝謝。那樣做了! –