Same name and namespace in other branches
  1. 7.x includes/bootstrap.inc \watchdog_exception()
  2. 8.9.x core/includes/bootstrap.inc \watchdog_exception()
  3. 9 core/includes/bootstrap.inc \watchdog_exception()

Logs an exception.

This is a wrapper logging function which automatically decodes an exception.

Parameters

$type: The category to which this message belongs.

$exception: The exception that is going to be logged.

$message: The message to store in the log. If empty, a text that contains all useful information about the passed-in exception is used.

$variables: Array of variables to replace in the message on display or NULL if message is already translated or not possible to translate.

$severity: The severity of the message, as per RFC 3164.

$link: A link to associate with the message.

Deprecated

in drupal:10.1.0 and is removed from drupal:11.0.0. Use Use \Drupal\Core\Utility\Error::logException() instead.

See also

\Drupal\Core\Utility\Error::decodeException()

https://www.drupal.org/node/2932520

1 call to watchdog_exception()
LegacyBootstrapTest::testWatchdogException in core/tests/Drupal/KernelTests/Core/Bootstrap/LegacyBootstrapTest.php
Tests watchdog_exception() deprecation.

File

core/includes/bootstrap.inc, line 135
Functions that need to be loaded on every Drupal request.

Code

function watchdog_exception($type, Exception $exception, $message = NULL, $variables = [], $severity = RfcLogLevel::ERROR, $link = NULL) {
  @trigger_error('watchdog_exception() is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use \\Drupal\\Core\\Utility\\Error::logException() instead. See https://www.drupal.org/node/2932520', E_USER_DEPRECATED);

  // Use a default value if $message is not set.
  if (empty($message)) {
    $message = Error::DEFAULT_ERROR_MESSAGE;
  }
  if ($link) {
    $variables['link'] = $link;
  }
  $variables += Error::decodeException($exception);
  \Drupal::logger($type)
    ->log($severity, $message, $variables);
}