Symfony 未在生产日志中显示 PDO 异常

Symfony not showing PDO exceptions in production log

如果我的应用程序没有连接到数据库 (postgres),它将以默认错误页面结束,显示生产模式下臭名昭著的错误:

Oops! An Error Occurred
The server returned a "500 Internal Server Error".

在开发模式下我看到错误:

PDOException > Exception  > ConnectionException
An exception occurred in driver: SQLSTATE[08006] [7] could not connect to server: Connection refused

这些原因没有显示在日志中。服务器和 php 都没有记录。我唯一看到的是

172.19.0.1 - - [30/Oct/2020:09:58:25 +0000] "GET / HTTP/1.1" 500 831

这是我的独白配置:

monolog:
  handlers:
    main:
     type: fingers_crossed
     action_level: debug
     handler: nested

  nested:
     type: stream
     path: php://stdout
     level: debug

顺便说一句,我正在将 所有内容 记录到标准输出。

那么,如何将这些错误记录到日志中?

(Symfony 5.1,docker,apache2)

debug 详细度是 最高的 详细度。

祈祷处理程序只将等于或高于 action_level 的日志转发到指定的处理程序。

所以在你的情况下它只会转发 debug 条消息。

action_level: error 用于手指交叉处理程序,然后清除缓存以将 所有 日志转发到您案例中的 nested 处理程序。

可以在手指交叉处理程序的文档 Handlers that Modify Log Entries 中找到更多信息。