You are here

class RavenCommands in Raven: Sentry Integration 8.2

Same name and namespace in other branches
  1. 3.x src/Commands/RavenCommands.php \Drupal\raven\Commands\RavenCommands

Provides Drush commands for Raven module.

Hierarchy

  • class \Drupal\raven\Commands\RavenCommands extends \Drush\Commands\DrushCommands

Expanded class hierarchy of RavenCommands

1 string reference to 'RavenCommands'
drush.services.yml in ./drush.services.yml
drush.services.yml
1 service uses RavenCommands
raven.commands in ./drush.services.yml
\Drupal\raven\Commands\RavenCommands

File

src/Commands/RavenCommands.php, line 11

Namespace

Drupal\raven\Commands
View source
class RavenCommands extends DrushCommands {

  /**
   * The @logger.raven service.
   *
   * @var \Drupal\raven\Logger\Raven|null
   */
  protected $ravenLogger;

  /**
   * Injects Raven logger service.
   */
  public function setRavenLogger(Raven $raven_logger) {
    $this->ravenLogger = $raven_logger;
  }

  /**
   * Send a test message to Sentry.
   *
   * Because messages are sent to Sentry asynchronously, there is no guarantee
   * that the message was actually delivered successfully.
   *
   * @param string $message
   *   The message text.
   * @param array $options
   *   An associative array of options.
   *
   * @option level
   *   The message level (debug, info, warning, error, fatal).
   * @option logger
   *   The logger.
   *
   * @command raven:captureMessage
   * @usage drush raven:captureMessage
   *   Send test message to Sentry.
   * @usage drush raven:captureMessage --level=error --logger=foobar
   *   Send error message of type "foobar" to Sentry.
   * @usage drush raven:captureMessage 'Mic check.'
   *   Send "Mic check" message to Sentry.
   */
  public function captureMessage($message = 'Test message from Drush.', array $options = [
    'level' => 'info',
    'logger' => 'drush',
  ]) {
    if (!$this->ravenLogger) {
      throw new \Exception('Raven logger service not available.');
    }
    if (!$this->ravenLogger->client) {
      throw new \Exception('Raven client not available.');
    }
    $id = $this->ravenLogger->client
      ->captureMessage($message, [], [
      'level' => $options['level'],
      'logger' => $options['logger'],
    ]);
    if (!$id) {
      throw new \Exception('Send failed.');
    }
    if (method_exists($this
      ->logger(), 'success')) {
      $this
        ->logger()
        ->success(dt('Message sent as event %id.', [
        '%id' => $id,
      ]));
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RavenCommands::$ravenLogger protected property The @logger.raven service.
RavenCommands::captureMessage public function Send a test message to Sentry.
RavenCommands::setRavenLogger public function Injects Raven logger service.