简体   繁体   English

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

[英]How do you log php errors with CakePHP when debug is 0?

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: 我想在一个调试= 0的CakePHP站点上记录PHP错误。但是,即使我打开错误日志,如下所示:

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. 问题是,即使是一个解析错误导致CakePHP环境没有完全加载(我认为),它仍然会阻止记录错误。 If I set debug to 3, it logs to the file without issue. 如果我将debug设置为3,它会毫无问题地记录到该文件。

I am using CakePHP 1.2. 我正在使用CakePHP 1.2。 I know this is apparently made easier in 1.3, but I'm not ready to upgrade. 我知道这显然在1.3中变得更容易了,但我还没准备好升级。

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

There is a bug in CakePHP 1.2-1.3 where PHP errors/warnings are suppressed in view code when debugging is disabled. CakePHP 1.2-1.3中存在一个错误,当禁用调试时,视图代码中的PHP错误/警告被禁止。

In the file cake/libs/view/view.php on line #664 it reads 在#664行的文件cake / libs / view / view.php中读取

@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. 这允许在视图代码中生成PHP错误/警告,然后记录。 Once I changed this and had the right logging settings in core.php I was finally able to get complete logs in production. 一旦我更改了这个并在core.php中有正确的日志记录设置,我终于能够获得完整的生产日志。

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

PHP should log errors to its own logfile, regardless of what CakePhp is doing. 无论CakePhp在做什么,PHP都应该将错误记录到自己的日志文件中。

Look in /etc/php.ini file (or wherever yours lives) and search for error_log . 查看/etc/php.ini文件(或您所在的任何地方)并搜索error_log This will show you where the PHP log resides on your system. 这将显示PHP日志驻留在系统上的位置。

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. 通常,这些文件将命名为filename.ext.r123,依此类推。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM