diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 04763a2210..b1e40a2d23 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -417,7 +417,7 @@ function drupal_validate_utf8($text) { function watchdog_exception($type, Exception $exception, $message = NULL, $variables = [], $severity = RfcLogLevel::ERROR, $link = NULL) { @trigger_error('watchdog_exception() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal::logException() instead. See https://www.drupal.org/node/2932520', E_USER_DEPRECATED); $variables['link'] = $link; - (new ExceptionLogger(\Drupal::logger($type)))->log($severity, $exception, $message, $variables); + \Drupal::exceptionLogger($type)->log($severity, $exception, $message, $variables); } /** diff --git a/core/includes/update.inc b/core/includes/update.inc index d7fe942ebd..6810ad2ba2 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -183,7 +183,7 @@ function update_do_one($module, $number, $dependency_map, &$context) { // return the message for printing. // @see https://www.drupal.org/node/2564311 catch (Exception $e) { - watchdog_exception('update', $e); + \Drupal::exceptionLogger('update')->error($e); $variables = Error::decodeException($e); unset($variables['backtrace']); @@ -250,7 +250,7 @@ function update_invoke_post_update($function, &$context) { // for printing. // @see https://www.drupal.org/node/2564311 catch (Exception $e) { - watchdog_exception('update', $e); + \Drupal::exceptionLogger('update')->error($e); $variables = Error::decodeException($e); unset($variables['backtrace']); diff --git a/core/lib/Drupal.php b/core/lib/Drupal.php index 639d99c037..65e7ef9eb1 100644 --- a/core/lib/Drupal.php +++ b/core/lib/Drupal.php @@ -6,6 +6,7 @@ */ use Drupal\Core\DependencyInjection\ContainerNotInitializedException; +use Drupal\Core\Logger\ExceptionLogger; use Drupal\Core\Messenger\LegacyMessenger; use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -708,6 +709,20 @@ public static function logger($channel) { return static::getContainer()->get('logger.factory')->get($channel); } + /** + * Gets an exception logger. + * + * @param string $channel + * The name of the channel. Can be any string, but the general practice is + * to use the name of the subsystem calling this. + * + * @return \Drupal\Core\Logger\ExceptionLogger + * The exception logger. + */ + public static function exceptionLogger($channel) { + return new ExceptionLogger(static::logger($channel)); + } + /** * Returns the menu tree. * diff --git a/core/lib/Drupal/Core/Cron.php b/core/lib/Drupal/Core/Cron.php index fb097ced9d..ad9edc4013 100644 --- a/core/lib/Drupal/Core/Cron.php +++ b/core/lib/Drupal/Core/Cron.php @@ -188,7 +188,7 @@ protected function processQueues() { // release the item and skip to the next queue. $queue->releaseItem($item); - watchdog_exception('cron', $e); + \Drupal::exceptionLogger('cron')->error($e); // Skip to the next queue. continue 2; @@ -196,7 +196,7 @@ protected function processQueues() { catch (\Exception $e) { // In case of any other kind of exception, log it and leave the item // in the queue to be processed again later. - watchdog_exception('cron', $e); + \Drupal::exceptionLogger('cron')->error($e); } } } @@ -235,7 +235,7 @@ protected function invokeCronHandlers() { $this->moduleHandler->invoke($module, 'cron'); } catch (\Exception $e) { - watchdog_exception('cron', $e); + \Drupal::exceptionLogger('cron')->error($e); } Timer::stop('cron_' . $module); diff --git a/core/lib/Drupal/Core/Database/Transaction.php b/core/lib/Drupal/Core/Database/Transaction.php index 837afda6de..f123407479 100644 --- a/core/lib/Drupal/Core/Database/Transaction.php +++ b/core/lib/Drupal/Core/Database/Transaction.php @@ -82,12 +82,10 @@ public function name() { * * This is just a wrapper method to rollback whatever transaction stack we are * currently in, which is managed by the connection object itself. Note that - * logging (preferable with watchdog_exception()) needs to happen after a - * transaction has been rolled back or the log messages will be rolled back - * too. + * database logging needs to happen after a transaction has been rolled back + * or the log messages will be rolled back too. * * @see \Drupal\Core\Database\Connection::rollBack() - * @see watchdog_exception() */ public function rollBack() { $this->rolledBack = TRUE; diff --git a/core/lib/Drupal/Core/Database/database.api.php b/core/lib/Drupal/Core/Database/database.api.php index 4cf34f8dd3..0604353598 100644 --- a/core/lib/Drupal/Core/Database/database.api.php +++ b/core/lib/Drupal/Core/Database/database.api.php @@ -183,7 +183,7 @@ * // Something went wrong somewhere, so roll back now. * $transaction->rollBack(); * // Log the exception to watchdog. - * watchdog_exception('type', $e); + * \Drupal::exceptionLogger('type')->error($e); * } * * // $transaction goes out of scope here. Unless the transaction was rolled diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php index ed01f22f29..10db495e12 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php @@ -730,7 +730,7 @@ public function delete(array $entities) { } catch (\Exception $e) { $transaction->rollBack(); - watchdog_exception($this->entityTypeId, $e); + \Drupal::exceptionLogger($this->entityTypeId)->error($e); throw new EntityStorageException($e->getMessage(), $e->getCode(), $e); } } @@ -782,7 +782,7 @@ public function save(EntityInterface $entity) { } catch (\Exception $e) { $transaction->rollBack(); - watchdog_exception($this->entityTypeId, $e); + \Drupal::exceptionLogger($this->entityTypeId)->error($e); throw new EntityStorageException($e->getMessage(), $e->getCode(), $e); } } diff --git a/core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php index bc606b4e9c..3b73bc717c 100644 --- a/core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php @@ -75,7 +75,7 @@ protected function menuLinksRebuild() { } catch (\Exception $e) { $transaction->rollBack(); - watchdog_exception('menu', $e); + \Drupal::exceptionLogger('menu')->error($e); } $this->lock->release(__FUNCTION__); diff --git a/core/lib/Drupal/Core/Routing/MatcherDumper.php b/core/lib/Drupal/Core/Routing/MatcherDumper.php index f19b0eed8d..ac8ffd7d1f 100644 --- a/core/lib/Drupal/Core/Routing/MatcherDumper.php +++ b/core/lib/Drupal/Core/Routing/MatcherDumper.php @@ -144,7 +144,7 @@ public function dump(array $options = []) { } catch (\Exception $e) { $transaction->rollBack(); - watchdog_exception('Routing', $e); + \Drupal::exceptionLogger('Routing')->error($e); throw $e; } // Sort the masks so they are in order of descending fit. diff --git a/core/modules/aggregator/src/ItemsImporter.php b/core/modules/aggregator/src/ItemsImporter.php index aa18d65c9a..456dff5880 100644 --- a/core/modules/aggregator/src/ItemsImporter.php +++ b/core/modules/aggregator/src/ItemsImporter.php @@ -91,7 +91,7 @@ public function refresh(FeedInterface $feed) { } catch (PluginException $e) { $success = FALSE; - watchdog_exception('aggregator', $e); + \Drupal::exceptionLogger('aggregator')->error($e); } // Store instances in an array so we dont have to instantiate new objects. @@ -101,7 +101,7 @@ public function refresh(FeedInterface $feed) { $processor_instances[$processor] = $this->processorManager->createInstance($processor); } catch (PluginException $e) { - watchdog_exception('aggregator', $e); + \Drupal::exceptionLogger('aggregator')->error($e); } } @@ -138,7 +138,7 @@ public function refresh(FeedInterface $feed) { } } catch (PluginException $e) { - watchdog_exception('aggregator', $e); + \Drupal::exceptionLogger('aggregator')->error($e); } } diff --git a/core/modules/aggregator/src/Plugin/aggregator/parser/DefaultParser.php b/core/modules/aggregator/src/Plugin/aggregator/parser/DefaultParser.php index 2694042104..2b21b1806f 100644 --- a/core/modules/aggregator/src/Plugin/aggregator/parser/DefaultParser.php +++ b/core/modules/aggregator/src/Plugin/aggregator/parser/DefaultParser.php @@ -33,7 +33,7 @@ public function parse(FeedInterface $feed) { $channel = Reader::importString($feed->source_string); } catch (ExceptionInterface $e) { - watchdog_exception('aggregator', $e); + \Drupal::exceptionLogger('aggregator')->error($e); $this->messenger()->addError(t('The feed from %site seems to be broken because of error "%error".', ['%site' => $feed->label(), '%error' => $e->getMessage()])); return FALSE; diff --git a/core/modules/update/src/UpdateFetcher.php b/core/modules/update/src/UpdateFetcher.php index 2b03c9c101..1376adbb8f 100644 --- a/core/modules/update/src/UpdateFetcher.php +++ b/core/modules/update/src/UpdateFetcher.php @@ -66,7 +66,7 @@ public function fetchProjectData(array $project, $site_key = '') { ->getBody(); } catch (RequestException $exception) { - watchdog_exception('update', $exception); + \Drupal::exceptionLogger('update')->error($exception); } return $data; } diff --git a/core/modules/workspaces/src/WorkspacePublisher.php b/core/modules/workspaces/src/WorkspacePublisher.php index 302b1a8e45..502b0c05b4 100644 --- a/core/modules/workspaces/src/WorkspacePublisher.php +++ b/core/modules/workspaces/src/WorkspacePublisher.php @@ -90,7 +90,7 @@ public function publish() { } catch (\Exception $e) { $transaction->rollBack(); - watchdog_exception('workspaces', $e); + \Drupal::exceptionLogger('workspaces')->error($e); throw $e; }