mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-10 15:14:14 +02:00
Tweak RollbarHandler to use proper levels and include level and level_name in context info, fixes #852
This commit is contained in:
@@ -21,6 +21,14 @@ use Monolog\Logger;
|
|||||||
* If the context data contains a `payload` key, that is used as an array
|
* If the context data contains a `payload` key, that is used as an array
|
||||||
* of payload options to RollbarNotifier's report_message/report_exception methods.
|
* of payload options to RollbarNotifier's report_message/report_exception methods.
|
||||||
*
|
*
|
||||||
|
* Rollbar's context info will contain the context + extra keys from the log record
|
||||||
|
* merged, and then on top of that a few keys:
|
||||||
|
*
|
||||||
|
* - level (rollbar level name)
|
||||||
|
* - monolog_level (monolog level name, raw level, as rollbar only has 5 but monolog 8)
|
||||||
|
* - channel
|
||||||
|
* - datetime (unix timestamp)
|
||||||
|
*
|
||||||
* @author Paul Statezny <paulstatezny@gmail.com>
|
* @author Paul Statezny <paulstatezny@gmail.com>
|
||||||
*/
|
*/
|
||||||
class RollbarHandler extends AbstractProcessingHandler
|
class RollbarHandler extends AbstractProcessingHandler
|
||||||
@@ -32,6 +40,17 @@ class RollbarHandler extends AbstractProcessingHandler
|
|||||||
*/
|
*/
|
||||||
protected $rollbarNotifier;
|
protected $rollbarNotifier;
|
||||||
|
|
||||||
|
protected $levelMap = array(
|
||||||
|
Logger::DEBUG => 'debug',
|
||||||
|
Logger::INFO => 'info',
|
||||||
|
Logger::NOTICE => 'info',
|
||||||
|
Logger::WARNING => 'warning',
|
||||||
|
Logger::ERROR => 'error',
|
||||||
|
Logger::CRITICAL => 'critical',
|
||||||
|
Logger::ALERT => 'critical',
|
||||||
|
Logger::EMERGENCY => 'critical',
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Records whether any log records have been added since the last flush of the rollbar notifier
|
* Records whether any log records have been added since the last flush of the rollbar notifier
|
||||||
*
|
*
|
||||||
@@ -56,36 +75,29 @@ class RollbarHandler extends AbstractProcessingHandler
|
|||||||
*/
|
*/
|
||||||
protected function write(array $record)
|
protected function write(array $record)
|
||||||
{
|
{
|
||||||
if (isset($record['context']['exception']) && $record['context']['exception'] instanceof Exception) {
|
$context = $record['context'];
|
||||||
$context = $record['context'];
|
$payload = array();
|
||||||
|
if (isset($context['payload'])) {
|
||||||
|
$payload = $context['payload'];
|
||||||
|
unset($context['payload']);
|
||||||
|
}
|
||||||
|
$context = array_merge($context, $record['extra'], array(
|
||||||
|
'level' => $this->levelMap[$record['level']],
|
||||||
|
'monolog_level' => $record['level_name'],
|
||||||
|
'channel' => $record['channel'],
|
||||||
|
'datetime' => $record['datetime']->format('U'),
|
||||||
|
));
|
||||||
|
|
||||||
|
if (isset($context['exception']) && $context['exception'] instanceof Exception) {
|
||||||
$exception = $context['exception'];
|
$exception = $context['exception'];
|
||||||
unset($context['exception']);
|
unset($context['exception']);
|
||||||
|
|
||||||
$payload = array();
|
|
||||||
if (isset($context['payload'])) {
|
|
||||||
$payload = $context['payload'];
|
|
||||||
unset($context['payload']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->rollbarNotifier->report_exception($exception, $context, $payload);
|
$this->rollbarNotifier->report_exception($exception, $context, $payload);
|
||||||
} else {
|
} else {
|
||||||
$extraData = array(
|
|
||||||
'level' => $record['level'],
|
|
||||||
'channel' => $record['channel'],
|
|
||||||
'datetime' => $record['datetime']->format('U'),
|
|
||||||
);
|
|
||||||
|
|
||||||
$context = $record['context'];
|
|
||||||
$payload = array();
|
|
||||||
if (isset($context['payload'])) {
|
|
||||||
$payload = $context['payload'];
|
|
||||||
unset($context['payload']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->rollbarNotifier->report_message(
|
$this->rollbarNotifier->report_message(
|
||||||
$record['message'],
|
$record['message'],
|
||||||
$record['level_name'],
|
$context['level'],
|
||||||
array_merge($record['context'], $record['extra'], $extraData),
|
$context,
|
||||||
$payload
|
$payload
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user