32

Is there a way to silence all PHP errors, warnings and notices in Drupal? They are usefull on the devel site but they are a big security risk, and make the site look bad on live.

I know on Drupal 6 the page at admin/settings/error-reporting can stop Drupal from writing errors to the screen, but where can I find this in Drupal 7? It seems it is missing.

  • 3
    Do note, though, that errors have a very important role: they indicate that something is wrong. Surpressing that, does not solve the underlying problem. This is also called the "Russian Method": When the alarm-light in a nuclear plant starts blinking, just remove the lightbulb. Alarm-light no longer blinks; no problems. – berkes Nov 14 '11 at 10:00
  • Funny :). But I only suppress error on the production site. – drupal_stuff_alter Nov 14 '11 at 12:13
  • Drupal has the option to decide which errors should be displayed; not displayed errors are still recorded in the database, and shown in admin/reports/dblog. – kiamlaluno Nov 14 '11 at 17:03
  • @kiamlaluno, in production that is somewhat fine (yet presenting an error that a payment failed is always better then leaving your client in uncertainty). But in development and testing my experience is that errors pushed into dblog are neglegted. Drupalsites with hundreds of notices and warnings per hour logged there, is no exception. And real exceptions and errors are lost in the noise. Best is to push each and every notice hard into the face of the developer. – berkes Nov 14 '11 at 21:17
  • Right, but the OP seems to be interested to hide those errors in a production site. (See, "They are usefull on the devel site but they are a big security risk, and make the site look bad on live.") – kiamlaluno Nov 14 '11 at 21:21
29

The path changes, as in Drupal 7 the same page you would before see at admin/settings/error-reporting is now at admin/config/development/logging.

screenshot

  • 1
    For some reason, im not able to do this. On click of save my selection is getting reset. Is there a way I can change this manually in database or something like this?? – Niranjan N Raju Aug 11 '17 at 3:56
17

As suggested, in Administration » Configuration » Development (at /admin/config/development/logging) you can find the setting to disable displaying of error messages, but it won't disable error/notices completely.

It's because Drupal 7 enforces E_ALL, so they're still written to syslog and you can see them in Recent logs affecting your website performance.

To disable the notices completely, you'll have to add the following line into your settings.php or php.ini file:

ini_set('error_reporting', E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED);

Show all errors, except for notices and coding standards warnings.

To silence all PHP errors, which is not recommended, you may try to addin your settings file:

error_reporting(0); // Disable all errors.

See: error_reporting()


Responsible Drupal 7 core code for E_ALL logging (file: includes/bootstrap.inc):

// Enforce E_ALL, but allow users to set levels not part of E_ALL.
error_reporting(E_ALL | error_reporting());

See also:

4

One thing no one has mentioned that may be helpful for people to know is that Drupal 7 ignores all local system error reporting levels. So you can't use .htaccess or even php.ini to set php error reporting levels in Drupal.

There is a patch proposed for this in D8, but currently in D7 you're restricted to the 3 error masks –all, none, or errors & warnings– that are set on the admin page kiamlaluno indicated.

3

Settings are always in admin/config/development/logging :)

  • Thanks a lot! I still want to have the green notifications alive. Hope they won't dissapear. – drupal_stuff_alter Nov 14 '11 at 9:54
2

Not sure why the Drush method is so undocumented, but I have in my build script:

drush vset error_level 0

... which saves error messages to the log but doesn't show them on screen.

1

You may need to add quotes to the solution kenorb posted above:

ini_set('error_reporting', 'E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR');
  • This is wrong - those are constants, they should not be quoted. error_reporting is an integer value which is made up of the integer constants ORed together. It is not a string setting made up of constant names as you've got here. – datashaman Mar 15 '16 at 13:45
0

There is a module for that:

https://www.drupal.org/project/errorlevelpermission

From the project page:

So you can

  • have a sitebuilder role (or even a special debugger role) see errors and notices
  • have others not see errors and notices.

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.