ILIAS  release_5-2 Revision v5.2.25-18-g3f80b82851
Monolog\Handler\RavenHandler Class Reference

Handler to send messages to a Sentry (https://github.com/getsentry/sentry) server using raven-php (https://github.com/getsentry/raven-php) More...

+ Inheritance diagram for Monolog\Handler\RavenHandler:
+ Collaboration diagram for Monolog\Handler\RavenHandler:

Public Member Functions

 __construct (Raven_Client $ravenClient, $level=Logger::DEBUG, $bubble=true)
 
 handleBatch (array $records)
 {Handles a set of records at once.
Parameters
array$recordsThe records to handle (an array of record arrays)
} More...
 
 setBatchFormatter (FormatterInterface $formatter)
 Sets the formatter for the logs generated by handleBatch(). More...
 
 getBatchFormatter ()
 Gets the formatter for the logs generated by handleBatch(). More...
 
 setRelease ($value)
 
- Public Member Functions inherited from Monolog\Handler\AbstractProcessingHandler
 handle (array $record)
 {Handles a record.All records may be passed to this method, and the handler should discard those that it does not want to handle.The return value of this function controls the bubbling process of the handler stack. Unless the bubbling is interrupted (by returning true), the Logger class will keep on calling further handlers in the stack with a given log record.
Parameters
array$recordThe record to handle
Returns
Boolean true means that this handler handled the record, and that bubbling is not permitted. false means the record was either not processed or that this handler allows bubbling.
} More...
 
- Public Member Functions inherited from Monolog\Handler\AbstractHandler
 __construct ($level=Logger::DEBUG, $bubble=true)
 
 isHandling (array $record)
 {Checks whether the given record will be handled by this handler.This is mostly done for performance reasons, to avoid calling processors for nothing.Handlers should still check the record levels within handle(), returning false in isHandling() is no guarantee that handle() will not be called, and isHandling() might not be called for a given record.
Parameters
array$recordPartial log record containing only a level key
Returns
Boolean
} More...
 
 handleBatch (array $records)
 {Handles a set of records at once.
Parameters
array$recordsThe records to handle (an array of record arrays)
} More...
 
 close ()
 Closes the handler. More...
 
 pushProcessor ($callback)
 {Adds a processor in the stack.
Parameters
callable$callback
Returns
self
} More...
 
 popProcessor ()
 {Removes the processor on top of the stack and returns it.
Returns
callable
} More...
 
 setFormatter (FormatterInterface $formatter)
 {Sets the formatter.
Parameters
FormatterInterface$formatter
Returns
self
} More...
 
 getFormatter ()
 {Gets the formatter.
Returns
FormatterInterface
} More...
 
 setLevel ($level)
 Sets minimum logging level at which this handler will be triggered. More...
 
 getLevel ()
 Gets minimum logging level at which this handler will be triggered. More...
 
 setBubble ($bubble)
 Sets the bubbling behavior. More...
 
 getBubble ()
 Gets the bubbling behavior. More...
 
 __destruct ()
 

Protected Member Functions

 write (array $record)
 {} More...
 
 getDefaultFormatter ()
 
 getDefaultBatchFormatter ()
 Gets the default formatter for the logs generated by handleBatch(). More...
 
 getExtraParameters ()
 Gets extra parameters supported by Raven that can be found in "extra" and "context". More...
 
- Protected Member Functions inherited from Monolog\Handler\AbstractProcessingHandler
 write (array $record)
 Writes the record down to the log of the implementing handler. More...
 
 processRecord (array $record)
 Processes a record. More...
 
- Protected Member Functions inherited from Monolog\Handler\AbstractHandler
 getDefaultFormatter ()
 Gets the default formatter. More...
 

Protected Attributes

 $ravenClient
 
 $batchFormatter
 
- Protected Attributes inherited from Monolog\Handler\AbstractHandler
 $level = Logger::DEBUG
 
 $bubble = true
 
 $formatter
 
 $processors = array()
 

Private Attributes

 $logLevels
 Translates Monolog log levels to Raven log levels. More...
 
 $release
 

Detailed Description

Handler to send messages to a Sentry (https://github.com/getsentry/sentry) server using raven-php (https://github.com/getsentry/raven-php)

Author
Marc Abramowitz marc@.nosp@m.marc.nosp@m.-abra.nosp@m.mowi.nosp@m.tz.co.nosp@m.m

Definition at line 25 of file RavenHandler.php.

Constructor & Destructor Documentation

◆ __construct()

Monolog\Handler\RavenHandler::__construct ( Raven_Client  $ravenClient,
  $level = Logger::DEBUG,
  $bubble = true 
)
Parameters
Raven_Client$ravenClient
int$levelThe minimum logging level at which this handler will be triggered
Boolean$bubbleWhether the messages that are handled can bubble up the stack or not

Definition at line 62 of file RavenHandler.php.

References Monolog\Handler\AbstractHandler\$bubble, Monolog\Handler\AbstractHandler\$level, and Monolog\Handler\RavenHandler\$ravenClient.

63  {
64  parent::__construct($level, $bubble);
65 
66  $this->ravenClient = $ravenClient;
67  }

Member Function Documentation

◆ getBatchFormatter()

Monolog\Handler\RavenHandler::getBatchFormatter ( )

Gets the formatter for the logs generated by handleBatch().

Returns
FormatterInterface

Definition at line 122 of file RavenHandler.php.

References Monolog\Handler\RavenHandler\$batchFormatter, and Monolog\Handler\RavenHandler\getDefaultBatchFormatter().

Referenced by Monolog\Handler\RavenHandler\handleBatch().

123  {
124  if (!$this->batchFormatter) {
125  $this->batchFormatter = $this->getDefaultBatchFormatter();
126  }
127 
128  return $this->batchFormatter;
129  }
getDefaultBatchFormatter()
Gets the default formatter for the logs generated by handleBatch().
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDefaultBatchFormatter()

Monolog\Handler\RavenHandler::getDefaultBatchFormatter ( )
protected

Gets the default formatter for the logs generated by handleBatch().

Returns
FormatterInterface

Definition at line 207 of file RavenHandler.php.

Referenced by Monolog\Handler\RavenHandler\getBatchFormatter().

208  {
209  return new LineFormatter();
210  }
+ Here is the caller graph for this function:

◆ getDefaultFormatter()

Monolog\Handler\RavenHandler::getDefaultFormatter ( )
protected

Definition at line 197 of file RavenHandler.php.

198  {
199  return new LineFormatter('[%channel%] %message%');
200  }

◆ getExtraParameters()

Monolog\Handler\RavenHandler::getExtraParameters ( )
protected

Gets extra parameters supported by Raven that can be found in "extra" and "context".

Returns
array

Definition at line 217 of file RavenHandler.php.

References array.

Referenced by Monolog\Handler\RavenHandler\write().

218  {
219  return array('checksum', 'release');
220  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ handleBatch()

LineFormatter The formatter to use for the logs generated via Monolog\Handler\RavenHandler::handleBatch ( array  $records)

{Handles a set of records at once.

Parameters
array$recordsThe records to handle (an array of record arrays)
}

Implements Monolog\Handler\HandlerInterface.

Definition at line 72 of file RavenHandler.php.

References Monolog\Handler\AbstractHandler\$level, $r, array, Monolog\Handler\RavenHandler\getBatchFormatter(), Monolog\Handler\AbstractProcessingHandler\handle(), Monolog\Handler\AbstractProcessingHandler\processRecord(), and string.

73  {
75 
76  // filter records based on their level
77  $records = array_filter($records, function ($record) use ($level) {
78  return $record['level'] >= $level;
79  });
80 
81  if (!$records) {
82  return;
83  }
84 
85  // the record with the highest severity is the "main" one
86  $record = array_reduce($records, function ($highest, $record) {
87  if ($record['level'] >= $highest['level']) {
88  return $record;
89  }
90 
91  return $highest;
92  });
93 
94  // the other ones are added as a context item
95  $logs = array();
96  foreach ($records as $r) {
97  $logs[] = $this->processRecord($r);
98  }
99 
100  if ($logs) {
101  $record['context']['logs'] = (string) $this->getBatchFormatter()->formatBatch($logs);
102  }
103 
104  $this->handle($record);
105  }
Add rich text string
The name of the decorator.
$records
Definition: simple_test.php:22
$r
Definition: example_031.php:79
handle(array $record)
{Handles a record.All records may be passed to this method, and the handler should discard those that...
Create styles array
The data for the language used.
processRecord(array $record)
Processes a record.
getBatchFormatter()
Gets the formatter for the logs generated by handleBatch().
+ Here is the call graph for this function:

◆ setBatchFormatter()

Monolog\Handler\RavenHandler::setBatchFormatter ( FormatterInterface  $formatter)

Sets the formatter for the logs generated by handleBatch().

Parameters
FormatterInterface$formatter

Definition at line 112 of file RavenHandler.php.

References Monolog\Handler\AbstractHandler\$formatter.

113  {
114  $this->batchFormatter = $formatter;
115  }

◆ setRelease()

Monolog\Handler\RavenHandler::setRelease (   $value)
Parameters
string$value

Definition at line 225 of file RavenHandler.php.

226  {
227  $this->release = $value;
228 
229  return $this;
230  }

◆ write()

Monolog\Handler\RavenHandler::write ( array  $record)
protected

{}

Definition at line 134 of file RavenHandler.php.

References $options, Monolog\Handler\RavenHandler\$release, array, and Monolog\Handler\RavenHandler\getExtraParameters().

135  {
136  $previousUserContext = false;
137  $options = array();
138  $options['level'] = $this->logLevels[$record['level']];
139  $options['tags'] = array();
140  if (!empty($record['extra']['tags'])) {
141  $options['tags'] = array_merge($options['tags'], $record['extra']['tags']);
142  unset($record['extra']['tags']);
143  }
144  if (!empty($record['context']['tags'])) {
145  $options['tags'] = array_merge($options['tags'], $record['context']['tags']);
146  unset($record['context']['tags']);
147  }
148  if (!empty($record['context']['fingerprint'])) {
149  $options['fingerprint'] = $record['context']['fingerprint'];
150  unset($record['context']['fingerprint']);
151  }
152  if (!empty($record['context']['logger'])) {
153  $options['logger'] = $record['context']['logger'];
154  unset($record['context']['logger']);
155  } else {
156  $options['logger'] = $record['channel'];
157  }
158  foreach ($this->getExtraParameters() as $key) {
159  foreach (array('extra', 'context') as $source) {
160  if (!empty($record[$source][$key])) {
161  $options[$key] = $record[$source][$key];
162  unset($record[$source][$key]);
163  }
164  }
165  }
166  if (!empty($record['context'])) {
167  $options['extra']['context'] = $record['context'];
168  if (!empty($record['context']['user'])) {
169  $previousUserContext = $this->ravenClient->context->user;
170  $this->ravenClient->user_context($record['context']['user']);
171  unset($options['extra']['context']['user']);
172  }
173  }
174  if (!empty($record['extra'])) {
175  $options['extra']['extra'] = $record['extra'];
176  }
177 
178  if (!empty($this->release) && !isset($options['release'])) {
179  $options['release'] = $this->release;
180  }
181 
182  if (isset($record['context']['exception']) && $record['context']['exception'] instanceof \Exception) {
183  $options['extra']['message'] = $record['formatted'];
184  $this->ravenClient->captureException($record['context']['exception'], $options);
185  } else {
186  $this->ravenClient->captureMessage($record['formatted'], array(), $options);
187  }
188 
189  if ($previousUserContext !== false) {
190  $this->ravenClient->user_context($previousUserContext);
191  }
192  }
getExtraParameters()
Gets extra parameters supported by Raven that can be found in "extra" and "context".
if(!is_array($argv)) $options
Create styles array
The data for the language used.
+ Here is the call graph for this function:

Field Documentation

◆ $batchFormatter

Monolog\Handler\RavenHandler::$batchFormatter
protected

Definition at line 55 of file RavenHandler.php.

Referenced by Monolog\Handler\RavenHandler\getBatchFormatter().

◆ $logLevels

Monolog\Handler\RavenHandler::$logLevels
private
Initial value:
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,
)

Translates Monolog log levels to Raven log levels.

Definition at line 30 of file RavenHandler.php.

◆ $ravenClient

Monolog\Handler\RavenHandler::$ravenClient
protected

Definition at line 50 of file RavenHandler.php.

Referenced by Monolog\Handler\RavenHandler\__construct().

◆ $release

Monolog\Handler\RavenHandler::$release
private

Definition at line 45 of file RavenHandler.php.

Referenced by Monolog\Handler\RavenHandler\write().


The documentation for this class was generated from the following file: