You are here

class Raven in Raven: Sentry Integration 8

Same name and namespace in other branches
  1. 8.2 src/Logger/Raven.php \Drupal\raven\Logger\Raven
  2. 3.x src/Logger/Raven.php \Drupal\raven\Logger\Raven

Hierarchy

Expanded class hierarchy of Raven

4 string references to 'Raven'
raven.info.yml in ./raven.info.yml
raven.info.yml
raven.links.menu.yml in ./raven.links.menu.yml
raven.links.menu.yml
raven.routing.yml in ./raven.routing.yml
raven.routing.yml
raven.services.yml in ./raven.services.yml
raven.services.yml
1 service uses Raven
logger.raven in ./raven.services.yml
Drupal\raven\Logger\Raven

File

src/Logger/Raven.php, line 12

Namespace

Drupal\raven\Logger
View source
class Raven implements LoggerInterface {
  use RfcLoggerTrait;

  /**
   * Raven client.
   */
  protected $client;

  /**
   * A configuration object containing syslog settings.
   *
   * @var \Drupal\Core\Config\Config
   */
  protected $config;

  /**
   * The message's placeholders parser.
   *
   * @var \Drupal\Core\Logger\LogMessageParserInterface
   */
  protected $parser;

  /**
   * Constructs a Raven log object.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The configuration factory object.
   * @param \Drupal\Core\Logger\LogMessageParserInterface $parser
   *   The parser to use when extracting message variables.
   */
  public function __construct(ConfigFactoryInterface $config_factory, LogMessageParserInterface $parser) {
    if (!class_exists('Raven_Client')) {

      // Sad raven.
      return;
    }
    $this->config = $config_factory
      ->get('raven.settings');
    $this->parser = $parser;
    $this->client = new Raven_Client($this->config
      ->get('client_key'), [
      'auto_log_stacks' => $this->config
        ->get('stack'),
      'curl_method' => 'async',
      'processorOptions' => [
        'Raven_SanitizeDataProcessor' => [
          'fields_re' => '/(SESS|pass|authorization|password|passwd|secret|password_confirmation|card_number|auth_pw)/i',
        ],
      ],
      'timeout' => $this->config
        ->get('timeout'),
      'trace' => $this->config
        ->get('trace'),
    ]);

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

  /**
   * {@inheritdoc}
   */
  public function log($level, $message, array $context = []) {
    if (!class_exists('Raven_Client')) {

      // Sad raven.
      return;
    }
    if (empty($this->config
      ->get('log_levels')[$level + 1])) {
      return;
    }
    $levels = [
      RfcLogLevel::EMERGENCY => Raven_Client::FATAL,
      RfcLogLevel::ALERT => Raven_Client::FATAL,
      RfcLogLevel::CRITICAL => Raven_Client::FATAL,
      RfcLogLevel::ERROR => Raven_Client::ERROR,
      RfcLogLevel::WARNING => Raven_Client::WARNING,
      RfcLogLevel::NOTICE => Raven_Client::INFO,
      RfcLogLevel::INFO => Raven_Client::INFO,
      RfcLogLevel::DEBUG => Raven_Client::DEBUG,
    ];
    $data['level'] = $levels[$level];
    $message_placeholders = $this->parser
      ->parseMessagePlaceholders($message, $context);
    $data['message'] = empty($message_placeholders) ? $message : strtr($message, $message_placeholders);
    $data['tags']['channel'] = $context['channel'];
    $data['extra']['link'] = $context['link'];
    $data['extra']['referer'] = $context['referer'];
    $data['extra']['request_uri'] = $context['request_uri'];
    $data['extra']['timestamp'] = $context['timestamp'];
    $data['user']['id'] = $context['uid'];
    $data['user']['ip_address'] = $context['ip'];
    $this->client
      ->capture($data, NULL);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Raven::$client protected property Raven client.
Raven::$config protected property A configuration object containing syslog settings.
Raven::$parser protected property The message's placeholders parser.
Raven::log public function Logs with an arbitrary level. Overrides RfcLoggerTrait::log
Raven::__construct public function Constructs a Raven log object.
RfcLoggerTrait::alert public function
RfcLoggerTrait::critical public function
RfcLoggerTrait::debug public function
RfcLoggerTrait::emergency public function
RfcLoggerTrait::error public function
RfcLoggerTrait::info public function
RfcLoggerTrait::notice public function
RfcLoggerTrait::warning public function