【问题标题】:How to attach stack trace to error log messages in PHP?如何将堆栈跟踪附加到 PHP 中的错误日志消息?
【发布时间】:2021-01-23 16:16:15
【问题描述】:

我运行多个 WordPress 站点,这些站点具有来自多个不同作者的多个主题和插件。我总是检查我的错误日志并尝试联系作者以修复他们代码中的错误,但其中很多都被记录为:

PHP Deprecated:  wpmu_new_blog is <strong>deprecated</strong> since version 5.1.0! Use wp_insert_site instead. in /wp-includes/functions.php on line 5148
PHP Warning:  array_merge(): Argument #3 is not an array in /wp-includes/class-wp-customize-widgets.php on line 376
PHP Warning:  Error while sending QUERY packet. PID=23688 in /wp-includes/wp-db.php on line 2033
PHP Warning:  mysqli_real_connect(): (HY000/2002): No such file or directory in /wp-includes/wp-db.php on line 1635

如您所见,警告发生在 wp-include 内的文件中,所有插件/主题/核心作者都可以使用,因此我无法找出谁调用了已弃用的函数,传递了错误的函数参数或他们所做的任何事情。

我也无法在开发环境中轻松重现该错误,因为我不知道是什么操作触发了它。

如果我可以更改一些 PHP(甚至服务器)设置,这会导致堆栈跟踪附加到每个错误日志消息,一切都会变得容易得多。

这是其中之一,就像我的问题一样常见,Google 没有帮助,因为所有搜索结果都试图解释如何将堆栈跟踪附加到我自己的代码,而不是任何人的代码。

【问题讨论】:

    标签: php wordpress error-handling


    【解决方案1】:

    您可以将 Xdebug 扩展安装到 PHP,它会覆盖 PHP 的错误记录机制,并在启用时将堆栈跟踪添加到错误、警告等。见Xdebug documentation

    【讨论】:

      猜你喜欢
      • 2017-03-08
      • 1970-01-01
      • 2023-01-20
      • 1970-01-01
      • 2021-03-18
      • 2015-08-04
      • 1970-01-01
      • 2015-09-05
      • 1970-01-01
      相关资源
      最近更新 更多