public function ExceptionLoggingSubscriber::onError

public ExceptionLoggingSubscriber::onError(GetResponseForExceptionEvent $event)

Log not-otherwise-specified errors, including HTTP 500.

Parameters

\Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event: The event to process.

File

core/lib/Drupal/Core/EventSubscriber/ExceptionLoggingSubscriber.php, line 62

Class

ExceptionLoggingSubscriber
Log exceptions without further handling.

Namespace

Drupal\Core\EventSubscriber

Code

public function onError(GetResponseForExceptionEvent $event) {
  $exception = $event->getException();
  $error = Error::decodeException($exception);
  $this->logger->get('php')->log($error['severity_level'], '%type: @message in %function (line %line of %file).', $error);

  $is_critical = !$exception instanceof HttpExceptionInterface || $exception->getStatusCode() >= 500;
  if ($is_critical) {
    error_log(sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine()));
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!EventSubscriber!ExceptionLoggingSubscriber.php/function/ExceptionLoggingSubscriber::onError/8.1.x