Blame view

sources/apps/files_external/3rdparty/aws-sdk-php/Monolog/Handler/RavenHandler.php 2.85 KB
31b7f2792   Kload   Upgrade to ownclo...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
  <?php
  
  /*
   * This file is part of the Monolog package.
   *
   * (c) Jordi Boggiano <j.boggiano@seld.be>
   *
   * For the full copyright and license information, please view the LICENSE
   * file that was distributed with this source code.
   */
  
  namespace Monolog\Handler;
  
  use Monolog\Formatter\LineFormatter;
  use Monolog\Logger;
  use Monolog\Handler\AbstractProcessingHandler;
  use Raven_Client;
  
  /**
   * Handler to send messages to a Sentry (https://github.com/dcramer/sentry) server
   * using raven-php (https://github.com/getsentry/raven-php)
   *
   * @author Marc Abramowitz <marc@marc-abramowitz.com>
   */
  class RavenHandler extends AbstractProcessingHandler
  {
      /**
       * Translates Monolog log levels to Raven log levels.
       */
      private $logLevels = array(
          Logger::DEBUG     => Raven_Client::DEBUG,
          Logger::INFO      => Raven_Client::INFO,
          Logger::NOTICE    => Raven_Client::INFO,
          Logger::WARNING   => Raven_Client::WARNING,
          Logger::ERROR     => Raven_Client::ERROR,
          Logger::CRITICAL  => Raven_Client::FATAL,
          Logger::ALERT     => Raven_Client::FATAL,
          Logger::EMERGENCY => Raven_Client::FATAL,
      );
  
      /**
       * @var Raven_Client the client object that sends the message to the server
       */
      protected $ravenClient;
  
      /**
       * @param Raven_Client $ravenClient
       * @param integer $level The minimum logging level at which this handler will be triggered
       * @param Boolean $bubble Whether the messages that are handled can bubble up the stack or not
       */
      public function __construct(Raven_Client $ravenClient, $level = Logger::DEBUG, $bubble = true)
      {
          parent::__construct($level, $bubble);
  
          $this->ravenClient = $ravenClient;
      }
  
      /**
       * {@inheritdoc}
       */
      protected function write(array $record)
      {
          $level = $this->logLevels[$record['level']];
  
          $options = array();
          $options['level'] = $level;
          if (!empty($record['context'])) {
              $options['extra']['context'] = $record['context'];
          }
          if (!empty($record['extra'])) {
              $options['extra']['extra'] = $record['extra'];
          }
  
          $this->ravenClient->captureMessage(
              $record['formatted'],
              array(),                                                                  // $params - not used
              version_compare(Raven_Client::VERSION, '0.1.0', '>') ? $options : $level, // $level or $options
              false                                                                     // $stack
          );
          if ($record['level'] >= Logger::ERROR && isset($record['context']['exception'])) {
              $this->ravenClient->captureException($record['context']['exception']);
          }
      }
  
      /**
       * {@inheritDoc}
       */
      protected function getDefaultFormatter()
      {
          return new LineFormatter('[%channel%] %message%');
      }
  }