You are here

private static function cf_error::p_print_message in Common Functionality 7.2

Prints error messages to the screen.

This uses drupal_set_message() and watchdog() to print the messages.

Why: This facilitates printing the error messages without having each and every usage need to manually do so.

Parameters

cf_error_code $error: The error code class object associated with the error.

string $message: A string to display.

array $variables_array: An array of string substitutions for anything in the $message string.

string $additional: (optional) Additional information to present only in the watchdog logs. This does not get displayed via drupal_set_message().

See also

drupal_set_message()

watchdog()

watchdog_severity_levels()

4 calls to cf_error::p_print_message()
cf_error::p_failed_to in modules/cf_error/classes/cf_error.php
Reports that a specific operation failed for a specific item.
cf_error::p_invalid_variable in modules/cf_error/classes/cf_error.php
Reports variables as invalid to the watchdog system.
cf_error::p_on_exception in modules/cf_error/classes/cf_error.php
Reports php exceptions.
cf_error::p_on_query_execution in modules/cf_error/classes/cf_error.php
Reports query execution failures.

File

modules/cf_error/classes/cf_error.php, line 1485
Provides the derror exception class.

Class

cf_error

Code

private static function p_print_message(cf_error_code $error, $message, array $variables_array, $additional = "") {
  if (function_exists('user_access')) {
    switch ($error
      ->get_severity()) {
      case WATCHDOG_EMERGENCY:
        if (user_access('view cf emergency messages')) {
          drupal_set_message(t($message, $variables_array), 'error', FALSE);
        }
        break;
      case WATCHDOG_ALERT:
      case WATCHDOG_CRITICAL:
      case WATCHDOG_ERROR:
        if (user_access('view cf error messages')) {
          drupal_set_message(t($message, $variables_array), 'error', FALSE);
        }
        break;
      case WATCHDOG_WARNING:
        if (user_access('view cf warning messages')) {
          drupal_set_message(t($message, $variables_array), 'warning', FALSE);
        }
        break;
      case WATCHDOG_NOTICE:
      case WATCHDOG_INFO:
        if (user_access('view cf information messages')) {
          drupal_set_message(t($message, $variables_array), 'status', FALSE);
        }
        break;
      case WATCHDOG_DEBUG:
        if (user_access('view cf debug messages')) {
          drupal_set_message(t($message, $variables_array), 'status', FALSE);
        }
        break;
    }
  }
  $message .= $additional;
  static $show_backtrace;
  if (!isset($show_backtrace)) {
    $show_backtrace = variable_get('cf_error_backtrace_mode', self::BACKTRACE_MODE_SHORT);
  }
  if ($show_backtrace != self::BACKTRACE_MODE_NONE) {
    if ($show_backtrace == self::BACKTRACE_MODE_SHORT || $show_backtrace == self::BACKTRACE_MODE_MODERATE) {
      $short_backtrace = array();
      $full_backtrace = $error
        ->get_backtrace();
      $backtrace_size = count($full_backtrace);
      if ($backtrace_size > 0) {
        reset($full_backtrace);
        $short_backtrace[] =& $full_backtrace[0];
      }
      if ($backtrace_size > 1) {
        $short_backtrace[] =& $full_backtrace[1];
      }
      if ($backtrace_size > 2) {
        $short_backtrace[] =& $full_backtrace[2];
      }
      if ($show_backtrace == self::BACKTRACE_MODE_MODERATE) {
        if ($backtrace_size > 3) {
          $short_backtrace[] =& $full_backtrace[3];
        }
        if ($backtrace_size > 4) {
          $short_backtrace[] =& $full_backtrace[4];
        }
        if ($backtrace_size > 5) {
          $short_backtrace[] =& $full_backtrace[5];
        }
        if ($backtrace_size > 6) {
          $short_backtrace[] =& $full_backtrace[6];
        }
        if ($backtrace_size > 7) {
          $short_backtrace[] =& $full_backtrace[7];
        }
      }
      $variables_array['%cf_error-backtrace'] = self::p_generate_backtrace($short_backtrace);
    }
    else {
      $full_backtrace = $error
        ->get_backtrace();
      $variables_array['%cf_error-backtrace'] = self::p_generate_backtrace($full_backtrace);
    }
    $message .= " \nBacktrace: %cf_error-backtrace";
  }
  watchdog($error
    ->get_type(), $message, $variables_array, $error
    ->get_severity());
}