7

My ideal situation would be to always log errors to file, but only display errors to logged in Super Admins. This way I'll be able to tell if my users are triggering PHP errors even if they aren't logged in.

However, it appears as if displaying errors on screen is related to logging errors to the php error log (which I have at /var/log/apache2/php_errors.log).

For example, if I have $config['debug'] = 2; it displays errors on screen and they get recorded in the error log.

If I have $config['debug'] = 0;, nothing gets displayed on screen, and nothing gets recorded in the error logs, etc.

Is there a way I can always have PHP errors logged to file, while still maintaining ExpressionEngine's PHP error display preferences?

  • Are you able to edit your php.ini rather than just EE's files, or are you in a shared environment? – Tom Davies Dec 1 '12 at 19:05
  • Yep can edit php.ini – Richard Frank Dec 2 '12 at 6:47
8

You need to find and remove some calls to the error_reporting() PHP function. This is set by the main index.php file in EE, and is often changed by extensions and other add-ons. You'll need to search through your whole codebase to make sure to remove all of these calls.

The main culprit is the following section of index.php. When you have $config['debug'] = 1; or $config['debug'] = 2; set, the DEBUG constant here will be set to 1. If you have $config['debug'] = 0;, DEBUG will be 0.

Old block:

/*
 * --------------------------------------------------------------------
 *  Set the error reporting level
 * --------------------------------------------------------------------
 */ 
if (DEBUG == 1)
{
    error_reporting(E_ALL);
    @ini_set('display_errors', 1);
}
else
{
    error_reporting(0); 
}

New block:

/*
 * --------------------------------------------------------------------
 *  Set the error reporting level
 * --------------------------------------------------------------------
 */ 
error_reporting(E_ALL);
if (DEBUG == 1)
{
    @ini_set('display_errors', 1);
}
else
{
    @ini_set('display_errors', 0);
}

This new block ensures that error_reporting() is always on, but disables showing the errors if the user does not match the requirement set by your $config['debug'] value.

You may want to search your installed add-ons for ini_set() calls that override the error_log and more importantly display_errors values, since this would cause the errors to not be logged properly and/or to be shown even when the user is not an admin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.