You are here

public function Raven::__construct in Raven: Sentry Integration 8.2

Same name in this branch
  1. 8.2 src/Logger/Raven.php \Drupal\raven\Logger\Raven::__construct()
  2. 8.2 src/Plugin/CspReportingHandler/Raven.php \Drupal\raven\Plugin\CspReportingHandler\Raven::__construct()
Same name and namespace in other branches
  1. 8 src/Logger/Raven.php \Drupal\raven\Logger\Raven::__construct()
  2. 3.x src/Logger/Raven.php \Drupal\raven\Logger\Raven::__construct()

Constructs a Raven log object.

Parameters

\Drupal\Core\Config\ConfigFactoryInterface $config_factory: The configuration factory object.

\Drupal\Core\Logger\LogMessageParserInterface $parser: The parser to use when extracting message variables.

\Drupal\Core\Extension\ModuleHandlerInterface $module_handler: The module handler.

string $environment: The kernel.environment parameter.

\Drupal\Core\Session\AccountInterface|null $current_user: The current user (optional).

\Symfony\Component\HttpFoundation\RequestStack|null $request_stack: The request stack (optional).

\Drupal\Core\Site\Settings $settings: The settings array (optional).

File

src/Logger/Raven.php, line 114

Class

Raven
Logs events to Sentry.

Namespace

Drupal\raven\Logger

Code

public function __construct(ConfigFactoryInterface $config_factory, LogMessageParserInterface $parser, ModuleHandlerInterface $module_handler, $environment, AccountInterface $current_user = NULL, RequestStack $request_stack = NULL, Settings $settings = NULL) {
  $this->configFactory = $config_factory;
  $this->config = $this->configFactory
    ->get('raven.settings');
  $this->currentUser = $current_user;
  $this->requestStack = $request_stack;
  $this->moduleHandler = $module_handler;
  $this->parser = $parser;
  $this->environment = $this->config
    ->get('environment') ?: $environment;
  $this->settings = $settings ?: Settings::getInstance();
  $this
    ->setClient();

  // Raven can catch fatal errors which are not caught by the Drupal logger.
  if ($this->client && $this->config
    ->get('fatal_error_handler')) {
    $error_handler = new \Raven_ErrorHandler($this->client);
    $error_handler
      ->registerShutdownFunction($this->config
      ->get('fatal_error_handler_memory'));
    register_shutdown_function([
      $this->client,
      'onShutdown',
    ]);
  }

  // Add Drush console error event listener.
  if (function_exists('drush_main') && $this->config
    ->get('drush_error_handler') && method_exists('Drush\\Drush', 'service')) {
    Drush::service('eventDispatcher')
      ->addListener(ConsoleEvents::ERROR, [
      $this,
      'onConsoleError',
    ]);
  }
}