You are here

function logs_http_shutdown in Logs HTTP 8

Same name and namespace in other branches
  1. 7 logs_http.module \logs_http_shutdown()

Runs on shutdown to clean up and display developer information.

See also

\Drupal\logs_http\EventSubscriber\LogsHttpEventSubscriber

1 string reference to 'logs_http_shutdown'
LogsHttpEventSubscriber::onRequest in src/EventSubscriber/LogsHttpEventSubscriber.php
Initializes Logs http module requirements.

File

./logs_http.module, line 15
Logs HTTP module.

Code

function logs_http_shutdown() {

  /** @var \Drupal\logs_http\Logger\LogsHttpLogger $logs_http_logger */
  $logs_http_logger = \Drupal::service('logs_http.logs_http_logger');
  if (!$logs_http_logger
    ->isEnabled()) {
    return;
  }
  if (!($events = $logs_http_logger
    ->getEvents())) {
    return;
  }
  $url = $logs_http_logger
    ->getUrl();

  // Send events to logs.
  foreach ($events as $event) {
    $client = \Drupal::httpClient();
    try {

      // Send data to Logs.
      $client
        ->post($url, [
        'json' => $event,
        'headers' => $logs_http_logger
          ->getHttpHeaders(),
      ]);
    } catch (RequestException $e) {
    }
  }
}