5

Drupal 6's common.inc file includes:

  // Set the Drupal custom error handler.
  set_error_handler('_drupal_error_handler');

If I'm following the logic correctly, this results in all PHP errors going to Watchdog (if enabled).

I'd like to continue using Watchdog (not syslog or similar modules) for everything but PHP errors. PHP errors should go to a file (i.e., the error_log that is configured in php.ini).

I'd prefer not to patch Drupal to remove its use of set_error_handler(), so I'm looking for some ideas. Perhaps I can make my own call to set_error_handler() in a hook_init() or settings.php? Any ideas?

5

Yes, you can use your own error handler instead. You'd put this in your own module - I'm not sure if you would need to put it earlier than hook_init(), though, i.e. in hook_boot(). Check out the Devel module, which has an option for overriding the error handler to make debugging easier.

|improve this answer|||||
  • I can't believe it was right there under mu nose all the months that this has been bugging me. In the Devel settings, set Error Handler to "none", and php errors go to the error_log rather than watchdog. Thanks! – rcourtna Nov 10 '11 at 15:18
  • A bit more feedback, setting the Error Handler to "none" seems to only effect browsing by user 1 (admin), regular user browsing will still result in PHP errors going to the watchdog. – rcourtna Nov 10 '11 at 15:48
  • Decent workaround is to grant 'access devel information' to the anonymous and authenticated roles in development environments. Devel probably shouldn't be enabled in a production environment anyways. – rcourtna Nov 10 '11 at 17:40
  • Heh, looks like I gave a slightly convoluted answer that led to what you needed anyway! Glad to help. – wizonesolutions Nov 10 '11 at 18:41
0
/**
 * Implements hook_init().
 * Drupal sets an error handler that sends PHP errors to watchdog. Undo that.
 */
function mymodule_init() {
  restore_error_handler();
}
|improve this answer|||||

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.