class Raven in Raven: Sentry Integration 8
Same name and namespace in other branches
- 8.2 src/Logger/Raven.php \Drupal\raven\Logger\Raven
- 3.x src/Logger/Raven.php \Drupal\raven\Logger\Raven
Hierarchy
- class \Drupal\raven\Logger\Raven implements \Psr\Log\LoggerInterface uses RfcLoggerTrait
Expanded class hierarchy of Raven
4 string references to 'Raven'
1 service uses Raven
File
- src/
Logger/ Raven.php, line 12
Namespace
Drupal\raven\LoggerView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Raven:: |
protected | property | Raven client. | |
Raven:: |
protected | property | A configuration object containing syslog settings. | |
Raven:: |
protected | property | The message's placeholders parser. | |
Raven:: |
public | function |
Logs with an arbitrary level. Overrides RfcLoggerTrait:: |
|
Raven:: |
public | function | Constructs a Raven log object. | |
RfcLoggerTrait:: |
public | function | ||
RfcLoggerTrait:: |
public | function | ||
RfcLoggerTrait:: |
public | function | ||
RfcLoggerTrait:: |
public | function | ||
RfcLoggerTrait:: |
public | function | ||
RfcLoggerTrait:: |
public | function | ||
RfcLoggerTrait:: |
public | function | ||
RfcLoggerTrait:: |
public | function |