简体   繁体   中英

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:

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.

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

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.

define('LOG_ERROR', 2); in core.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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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