1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-04 20:27:31 +02:00

Merge pull request #332 from PaulStatezny/rollbar-handler

Add Rollbar handler
This commit is contained in:
Jordi Boggiano
2014-03-08 17:45:09 +01:00
3 changed files with 66 additions and 1 deletions

View File

@@ -133,6 +133,7 @@ Handlers
- _ZendMonitorHandler_: Logs records to the Zend Monitor present in Zend Server.
- _NewRelicHandler_: Logs records to a [NewRelic](http://newrelic.com/) application.
- _LogglyHandler_: Logs records to a [Loggly](http://www.loggly.com/) account.
- _RollbarHandler_: Logs records to a [Rollbar](https://rollbar.com/) account.
- _SyslogUdpHandler_: Logs records to a remote [Syslogd](http://www.rsyslog.com/) server.
### Logging in development

View File

@@ -31,7 +31,8 @@
"ruflin/elastica": "Allow sending log messages to an Elastic Search server",
"ext-amqp": "Allow sending log messages to an AMQP server (1.0+ required)",
"ext-mongo": "Allow sending log messages to a MongoDB server",
"aws/aws-sdk-php": "Allow sending log messages to AWS services like DynamoDB"
"aws/aws-sdk-php": "Allow sending log messages to AWS services like DynamoDB",
"rollbar/rollbar": "Allow sending log messages to Rollbar"
},
"autoload": {
"psr-4": {"Monolog\\": "src/Monolog"}

View File

@@ -0,0 +1,63 @@
<?php
namespace Monolog\Handler;
use RollbarNotifier;
use Exception;
/**
* Sends errors to Rollbar
*
* @author Paul Statezny <paulstatezny@gmail.com>
*/
class RollbarHandler extends AbstractProcessingHandler
{
/**
* Rollbar notifier
*
* @var RollbarNotifier
*/
protected $rollbarNotifier;
/**
* @param RollbarNotifier $rollbarNotifier RollbarNotifier object constructed with valid token
* @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(RollbarNotifier $rollbarNotifier, $level = Logger::ERROR, $bubble = true)
{
$this->rollbarNotifier = $rollbarNotifier;
parent::__construct($level, $bubble);
}
/**
* {@inheritdoc}
*/
protected function write(array $record)
{
if (isset($record['context']['exception']) && $record['context']['exception'] instanceof Exception) {
$this->rollbarNotifier->report_exception($record['context']['exception']);
} else {
$extraData = array(
'level' => $record['level'],
'channel' => $record['channel'],
'datetime' => $record['datetime']->format('U'),
);
$this->rollbarNotifier->report_message(
$record['message'],
$record['level_name'],
array_merge($record['context'], $record['extra'], $extraData)
);
}
}
/**
* {@inheritdoc}
*/
public function close()
{
$this->rollbarNotifier->flush();
}
}