ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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...
 
- 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 ()
 
 isHandling (array $record)
 Checks whether the given record will be handled by this handler. More...
 
 handle (array $record)
 Handles a record. More...
 
 handleBatch (array $records)
 Handles a set of records at once. More...
 
 pushProcessor ($callback)
 Adds a processor in the stack. More...
 
 popProcessor ()
 Removes the processor on top of the stack and returns it. More...
 
 setFormatter (FormatterInterface $formatter)
 Sets the formatter. More...
 
 getFormatter ()
 Gets the formatter. More...
 

Protected Member Functions

 write (array $record)
 {Writes the record down to the log of the implementing handler.
Parameters
array$record
Returns
void
} More...
 
 getDefaultFormatter ()
 Gets the default formatter.
Returns
FormatterInterface
More...
 
 getDefaultBatchFormatter ()
 Gets the default formatter for the logs generated by handleBatch(). 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...
 
 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...
 

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
integer$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 56 of file RavenHandler.php.

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

Member Function Documentation

◆ getBatchFormatter()

Monolog\Handler\RavenHandler::getBatchFormatter ( )

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

Returns
FormatterInterface

Definition at line 116 of file RavenHandler.php.

117 {
118 if (!$this->batchFormatter) {
119 $this->batchFormatter = $this->getDefaultBatchFormatter();
120 }
121
123 }
getDefaultBatchFormatter()
Gets the default formatter for the logs generated by handleBatch().

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

Referenced by Monolog\Handler\RavenHandler\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 186 of file RavenHandler.php.

187 {
188 return new LineFormatter();
189 }

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

+ Here is the caller graph for this function:

◆ getDefaultFormatter()

Monolog\Handler\RavenHandler::getDefaultFormatter ( )
protected

Gets the default formatter.

Returns
FormatterInterface

Reimplemented from Monolog\Handler\AbstractHandler.

Definition at line 176 of file RavenHandler.php.

177 {
178 return new LineFormatter('[%channel%] %message%');
179 }

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

Reimplemented from Monolog\Handler\AbstractHandler.

Definition at line 66 of file RavenHandler.php.

67 {
69
70 // filter records based on their level
71 $records = array_filter($records, function ($record) use ($level) {
72 return $record['level'] >= $level;
73 });
74
75 if (!$records) {
76 return;
77 }
78
79 // the record with the highest severity is the "main" one
80 $record = array_reduce($records, function ($highest, $record) {
81 if ($record['level'] >= $highest['level']) {
82 return $record;
83 }
84
85 return $highest;
86 });
87
88 // the other ones are added as a context item
89 $logs = array();
90 foreach ($records as $r) {
91 $logs[] = $this->processRecord($r);
92 }
93
94 if ($logs) {
95 $record['context']['logs'] = (string) $this->getBatchFormatter()->formatBatch($logs);
96 }
97
98 $this->handle($record);
99 }
handle(array $record)
{Handles a record.All records may be passed to this method, and the handler should discard those that...
processRecord(array $record)
Processes a record.
getBatchFormatter()
Gets the formatter for the logs generated by handleBatch().
$r
Definition: example_031.php:79
$records
Definition: simple_test.php:17

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

+ 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 106 of file RavenHandler.php.

107 {
108 $this->batchFormatter = $formatter;
109 }

References Monolog\Handler\AbstractHandler\$formatter.

◆ write()

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

{Writes the record down to the log of the implementing handler.

Parameters
array$record
Returns
void
}

Reimplemented from Monolog\Handler\AbstractProcessingHandler.

Definition at line 128 of file RavenHandler.php.

129 {
130 $previousUserContext = false;
131 $options = array();
132 $options['level'] = $this->logLevels[$record['level']];
133 $options['tags'] = array();
134 if (!empty($record['extra']['tags'])) {
135 $options['tags'] = array_merge($options['tags'], $record['extra']['tags']);
136 unset($record['extra']['tags']);
137 }
138 if (!empty($record['context']['tags'])) {
139 $options['tags'] = array_merge($options['tags'], $record['context']['tags']);
140 unset($record['context']['tags']);
141 }
142 if (!empty($record['context']['logger'])) {
143 $options['logger'] = $record['context']['logger'];
144 unset($record['context']['logger']);
145 } else {
146 $options['logger'] = $record['channel'];
147 }
148 if (!empty($record['context'])) {
149 $options['extra']['context'] = $record['context'];
150 if (!empty($record['context']['user'])) {
151 $previousUserContext = $this->ravenClient->context->user;
152 $this->ravenClient->user_context($record['context']['user']);
153 unset($options['extra']['context']['user']);
154 }
155 }
156 if (!empty($record['extra'])) {
157 $options['extra']['extra'] = $record['extra'];
158 }
159
160 if (isset($record['context']['exception']) && $record['context']['exception'] instanceof \Exception) {
161 $options['extra']['message'] = $record['formatted'];
162 $this->ravenClient->captureException($record['context']['exception'], $options);
163 } else {
164 $this->ravenClient->captureMessage($record['formatted'], array(), $options);
165 }
166
167 if ($previousUserContext !== false) {
168 $this->ravenClient->user_context($previousUserContext);
169 }
170
171 }
if(!is_array($argv)) $options

References $options.

Field Documentation

◆ $batchFormatter

Monolog\Handler\RavenHandler::$batchFormatter
protected

Definition at line 49 of file RavenHandler.php.

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

◆ $logLevels

Monolog\Handler\RavenHandler::$logLevels
private
Initial value:
= array(
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,
)
const EMERGENCY
Urgent alert.
Definition: Logger.php:77
const ERROR
Runtime errors.
Definition: Logger.php:57
const CRITICAL
Critical conditions.
Definition: Logger.php:64
const WARNING
Exceptional occurrences that are not errors.
Definition: Logger.php:52
const INFO
Interesting events.
Definition: Logger.php:39
const DEBUG
Detailed debug information.
Definition: Logger.php:32
const NOTICE
Uncommon events.
Definition: Logger.php:44
const ALERT
Action must be taken immediately.
Definition: Logger.php:72
const DEBUG

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 44 of file RavenHandler.php.

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


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