watchdog_exception - This is a wrapper function for watchdog() which automatically decodes an exception.

Public

bootstrap.inc

</> CopyGet raw version
php
  1. /**
  2.  * Logs an exception.
  3.  *
  4.  * This is a wrapper function for watchdog() which automatically decodes an
  5.  * exception.
  6.  *
  7.  * @param $type
  8.  * The category to which this message belongs.
  9.  * @param $exception
  10.  * The exception that is going to be logged.
  11.  * @param $message
  12.  * The message to store in the log. If empty, a text that contains all useful
  13.  * information about the passed-in exception is used.
  14.  * @param $variables
  15.  * Array of variables to replace in the message on display. Defaults to the
  16.  * return value of _drupal_decode_exception().
  17.  * @param $severity
  18.  * The severity of the message, as per RFC 3164.
  19.  * @param $link
  20.  * A link to associate with the message.
  21.  *
  22.  * @see watchdog()
  23.  * @see _drupal_decode_exception()
  24.  */
  25. function watchdog_exception($type, Exception $exception, $message = NULL, $variables = array(), $severity = WATCHDOG_ERROR, $link = NULL) {
  26.  
  27. // Use a default value if $message is not set.
  28. if (empty($message)) {
  29. // The exception message is run through check_plain() by _drupal_decode_exception().
  30. $message = '%type: !message in %function (line %line of %file).';
  31. }
  32. // $variables must be an array so that we can add the exception information.
  33. if (!is_array($variables)) {
  34. $variables = array();
  35. }
  36.  
  37. require_once DRUPAL_ROOT . '/includes/errors.inc';
  38. $variables += _drupal_decode_exception($exception);
  39. watchdog($type, $message, $variables, $severity, $link);
  40. }

Logs a system message.

</> CopyGet raw version
php
  1. /**
  2.  * Logs a system message.
  3.  *
  4.  * @param $type
  5.  * The category to which this message belongs. Can be any string, but the
  6.  * general practice is to use the name of the module calling watchdog().
  7.  * @param $message
  8.  * The message to store in the log. Keep $message translatable
  9.  * by not concatenating dynamic values into it! Variables in the
  10.  * message should be added by using placeholder strings alongside
  11.  * the variables argument to declare the value of the placeholders.
  12.  * See t() for documentation on how $message and $variables interact.
  13.  * @param $variables
  14.  * Array of variables to replace in the message on display or
  15.  * NULL if message is already translated or not possible to
  16.  * translate.
  17.  * @param $severity
  18.  * The severity of the message; one of the following values as defined in
  19.  * @link http://www.faqs.org/rfcs/rfc3164.html RFC 3164: @endlink
  20.  * - WATCHDOG_EMERGENCY: Emergency, system is unusable.
  21.  * - WATCHDOG_ALERT: Alert, action must be taken immediately.
  22.  * - WATCHDOG_CRITICAL: Critical conditions.
  23.  * - WATCHDOG_ERROR: Error conditions.
  24.  * - WATCHDOG_WARNING: Warning conditions.
  25.  * - WATCHDOG_NOTICE: (default) Normal but significant conditions.
  26.  * - WATCHDOG_INFO: Informational messages.
  27.  * - WATCHDOG_DEBUG: Debug-level messages.
  28.  * @param $link
  29.  * A link to associate with the message.
  30.  *
  31.  * @see watchdog_severity_levels()
  32.  * @see hook_watchdog()
  33.  */
  34. function watchdog($type, $message, $variables = array(), $severity = WATCHDOG_NOTICE, $link = NULL) {
  35. global $user, $base_root;
  36.  
  37. static $in_error_state = FALSE;
  38.  
  39. // It is possible that the error handling will itself trigger an error. In that case, we could
  40. // end up in an infinite loop. To avoid that, we implement a simple static semaphore.
  41. if (!$in_error_state && function_exists('module_implements')) {
  42. $in_error_state = TRUE;
  43.  
  44. // The user object may not exist in all conditions, so 0 is substituted if needed.
  45. $user_uid = isset($user->uid) ? $user->uid : 0;
  46.  
  47. // Prepare the fields to be logged
  48. $log_entry = array(
  49. 'type' => $type,
  50. 'message' => $message,
  51. 'variables' => $variables,
  52. 'severity' => $severity,
  53. 'link' => $link,
  54. 'user' => $user,
  55. 'uid' => $user_uid,
  56. 'request_uri' => $base_root . request_uri(),
  57. 'referer' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '',
  58. 'ip' => ip_address(),
  59. // Request time isn't accurate for long processes, use time() instead.
  60. 'timestamp' => time(),
  61. );
  62.  
  63. // Call the logging hooks to log/process the message
  64. foreach (module_implements('watchdog') as $module) {
  65. module_invoke($module, 'watchdog', $log_entry);
  66. }
  67.  
  68. // It is critical that the semaphore is only cleared here, in the parent
  69. // watchdog() call (not outside the loop), to prevent recursive execution.
  70. $in_error_state = FALSE;
  71. }
  72. }