You are here

public function Raven::log in Raven: Sentry Integration 8

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

Overrides RfcLoggerTrait::log

File

src/Logger/Raven.php, line 70

Class

Raven

Namespace

Drupal\raven\Logger

Code

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);
}