当 debug 为 0 时,如何使用 CakePHP 记录 php 错误?

发布于 2024-10-15 20:56:31 字数 329 浏览 1 评论 0原文

我想在 debug = 0 的 CakePHP 站点上记录 PHP 错误。但是,即使我打开错误日志,如下所示:

error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED
log_errors = On

它也不会记录错误。

问题是,即使对于导致 CakePHP 环境无法完全加载的解析错误(我认为),它仍然会阻止记录该错误。如果我将 debug 设置为 3,它会毫无问题地记录到文件中。

我正在使用 CakePHP 1.2。我知道这在 1.3 中显然变得更容易,但我还没有准备好升级。

I would like to log PHP errors on a CakePHP site that has debug = 0. However, even if I turn on the error log, like this:

error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED
log_errors = On

it doesn't log errors.

The problem is that even for a parse error that should cause the CakePHP environment to not load completely (I think), it still blocks the error from being logged. If I set debug to 3, it logs to the file without issue.

I am using CakePHP 1.2. I know this is apparently made easier in 1.3, but I'm not ready to upgrade.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

月下凄凉 2024-10-22 20:56:31

另一种跟踪和记录错误的方法是使用 Referee 插件,因为它提供了一种任意记录并捕获执行期间发生的所有(包括致命)错误。

Another way to keep track of and log errors would be to use the Referee plugin as it provides a way to arbitrarily log and catch all (including fatal) errors that occur during exection.

可是我不能没有你 2024-10-22 20:56:31

定义('LOG_ERROR', 2);在 core.php 中

define('LOG_ERROR', 2); in core.php

舂唻埖巳落 2024-10-22 20:56:31

PHP 应该将错误记录到自己的日志文件中,无论 CakePhp 在做什么。

查看 /etc/php.ini 文件(或您所在的任何位置)并搜索 error_log。这将显示 PHP 日志在系统上的位置。

PHP should log errors to its own logfile, regardless of what CakePhp is doing.

Look in /etc/php.ini file (or wherever yours lives) and search for error_log. This will show you where the PHP log resides on your system.

打小就很酷 2024-10-22 20:56:31

CakePHP 1.2-1.3 中存在一个错误,当禁用调试时,视图代码中会抑制 PHP 错误/警告。

在文件 cake/libs/view/view.php 的第 #664 行中,它显示

@include ($___viewFn);

但 @ 指令会抑制整个视图处理程序的错误。相反,它应该是:

include ($___viewFn);

允许在视图代码中生成 PHP 错误/警告并随后进行记录。一旦我更改了这一点并在 core.php 中设置了正确的日志记录设置,我终于能够在生产中获得完整的日志。

There is a bug in CakePHP 1.2-1.3 where PHP errors/warnings are suppressed in view code when debugging is disabled.

In the file cake/libs/view/view.php on line #664 it reads

@include ($___viewFn);

But the @ directive suppresses errors for the entire view handler. Instead it should be:

include ($___viewFn);

Which allows PHP errors/warnings to be generated in view code and subsequently get logged. Once I changed this and had the right logging settings in core.php I was finally able to get complete logs in production.

起风了 2024-10-22 20:56:31

有时原因可能非常不同。例如,您正在使用的框架可能有自己的内部缓存模块,该模块在您继续尝试时将值保留在缓冲区中。检查是否生成重复副本。通常这些文件将被命名为 filename.ext.r123 等。

Sometime the reason could be very different. For example the framework you are using may have its own internal caching module which keeps the value in buffer while you keep on trying. Check whether duplicate copies are getting generated or not. Typically those files would be named as filename.ext.r123 and so on.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文