我使用以下配置创建记录器:
'log' => [
'logger' => [
'writers' => [
'stream' => [
'name' => 'stream',
'priority' => \Zend\Log\Logger::INFO,
'options' => [
'stream' => __DIR__ . '/../../data/log/name_' . date("Ym") . '.log',
'formatter' => [
'name' => \Zend\Log\Formatter\Simple::class,
'options' => [
'format' => '%timestamp% %priorityName% : %message% %extra%',
'dateTimeFormat' => 'c',
],
],
],
],
],
'processors' => [
'requestid' => [
'name' => \Zend\Log\Processor\RequestId::class,
],
'backtrace' => [
'name' => \Zend\Log\Processor\Backtrace::class,
],
],
],
],
日志工作正常,但php错误未在任何地方记录。
为什么?
我使用此代码生成一个简单的错误
$d1 = new DateTime();
$d2 = new DateTime();
$a = array($d1,$d2);
$a->format("Y-m-d");
在我的控制器类中。
未记录此错误
答案 0 :(得分:0)
答案 1 :(得分:0)
zend-log默认不是异常或错误处理程序。您必须对其进行设置。您可以使用 exceptionhandler , errorhandler 和 fatal_error_shutdownfunction 选项进行设置。所有配置键均接受布尔值。这是一个例子。我没有测试,但应该是这样。
'log' => [
'logger' => [
'writers' => [
'stream' => [
'name' => 'stream',
'priority' => \Zend\Log\Logger::INFO,
'options' => [
'exceptionhandler' => true,
'errorhandler' => true,
'stream' => __DIR__ . '/../../data/log/name_' . date("Ym") . '.log',
'formatter' => [
'name' => \Zend\Log\Formatter\Simple::class,
'options' => [
'format' => '%timestamp% %priorityName% : %message% %extra%',
'dateTimeFormat' => 'c',
],
],
],
],
],
'processors' => [
'requestid' => [
'name' => \Zend\Log\Processor\RequestId::class,
],
'backtrace' => [
'name' => \Zend\Log\Processor\Backtrace::class,
],
],
],
],