8.5.x errors.inc _drupal_log_error($error, $fatal = FALSE)
8.0.x errors.inc _drupal_log_error($error, $fatal = FALSE)
8.1.x errors.inc _drupal_log_error($error, $fatal = FALSE)
8.2.x errors.inc _drupal_log_error($error, $fatal = FALSE)
8.3.x errors.inc _drupal_log_error($error, $fatal = FALSE)
8.4.x errors.inc _drupal_log_error($error, $fatal = FALSE)
8.6.x errors.inc _drupal_log_error($error, $fatal = FALSE)
7.x errors.inc _drupal_log_error($error, $fatal = FALSE)

Logs a PHP error or exception and displays an error page in fatal cases.


$error: An array with the following keys: %type, !message, %function, %file, %line and severity_level. All the parameters are plain-text, with the exception of !message, which needs to be a safe HTML string.

$fatal: TRUE if the error is fatal.

2 calls to _drupal_log_error()
_drupal_error_handler_real in includes/errors.inc
Provides custom PHP error handling.
_drupal_exception_handler in includes/bootstrap.inc
Provides custom PHP exception handling.


includes/errors.inc, line 171
Functions for error handling.


function _drupal_log_error($error, $fatal = FALSE) {

  // Initialize a maintenance theme if the bootstrap was not complete.
  // Do it early because drupal_set_message() triggers a drupal_theme_initialize().
  if ($fatal && drupal_get_bootstrap_phase() != DRUPAL_BOOTSTRAP_FULL) {
    if (!defined('MAINTENANCE_MODE')) {
      define('MAINTENANCE_MODE', 'error');

  // When running inside the testing framework, we relay the errors
  // to the tested site by the way of HTTP headers.
  $test_info =& $GLOBALS['drupal_test_info'];
  if (!empty($test_info['in_child_site']) && !headers_sent() && (!defined('SIMPLETEST_COLLECT_ERRORS') || SIMPLETEST_COLLECT_ERRORS)) {

    // $number does not use drupal_static as it should not be reset
    // as it uniquely identifies each PHP error.
    static $number = 0;
    $assertion = array(
        'function' => $error['%function'],
        'file' => $error['%file'],
        'line' => $error['%line'],
    header('X-Drupal-Assertion-' . $number . ': ' . rawurlencode(serialize($assertion)));

  // Log the error immediately, unless this is a non-fatal error which has been
  // triggered via drupal_trigger_error_with_delayed_logging(); in that case
  // trigger it in a shutdown function. Fatal errors are always triggered
  // immediately since for a fatal error the page request will end here anyway.
  if (!$fatal && drupal_static('_drupal_trigger_error_with_delayed_logging')) {
    drupal_register_shutdown_function('watchdog', 'php', '%type: !message in %function (line %line of %file).', $error, $error['severity_level']);
  else {
    watchdog('php', '%type: !message in %function (line %line of %file).', $error, $error['severity_level']);
  if ($fatal) {
    drupal_add_http_header('Status', '500 Service unavailable (with message)');
  if (drupal_is_cli()) {
    if ($fatal) {

      // When called from CLI, simply output a plain text message.
      print html_entity_decode(strip_tags(t('%type: !message in %function (line %line of %file).', $error))) . "\n";
  if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
    if ($fatal) {
      if (error_displayable($error)) {

        // When called from JavaScript, simply output the error message.
        print t('%type: !message in %function (line %line of %file).', $error);
  else {

    // Display the message if the current error reporting level allows this type
    // of message to be displayed, and unconditionally in update.php.
    if (error_displayable($error)) {
      $class = 'error';

      // If error type is 'User notice' then treat it as debug information
      // instead of an error message, see dd().
      if ($error['%type'] == 'User notice') {
        $error['%type'] = 'Debug';
        $class = 'status';
      drupal_set_message(t('%type: !message in %function (line %line of %file).', $error), $class);
    if ($fatal) {

      // We fallback to a maintenance page at this point, because the page generation
      // itself can generate errors.
      print theme('maintenance_page', array(
        'content' => t('The website encountered an unexpected error. Please try again later.'),


ChrisFlink’s picture

      '%type' => 'type'
      '!message' => filter_xss_admin($message), 
      '%function' => __FUNCTION__, 
      '%file' => __FILE__, 
      '%line' => __LINE__, 
      'severity_level' => $severity_level,
    ), $error_level == E_WARNING);

see http://php.net/manual/en/errorfunc.constants.php for php error level constants