mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-06 05:07:36 +02:00
add release number to every log
This adds an internal release number to the raven handler. The release number is added to what is sent to sentry unless something already is present because a release number was sent via "context" or "extra".
This commit is contained in:
@@ -38,6 +38,12 @@ class RavenHandler extends AbstractProcessingHandler
|
|||||||
Logger::EMERGENCY => Raven_Client::FATAL,
|
Logger::EMERGENCY => Raven_Client::FATAL,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string should represent the current version of the calling
|
||||||
|
* software. Can be any string (git commit, version number)
|
||||||
|
*/
|
||||||
|
private $release;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Raven_Client the client object that sends the message to the server
|
* @var Raven_Client the client object that sends the message to the server
|
||||||
*/
|
*/
|
||||||
@@ -169,6 +175,10 @@ class RavenHandler extends AbstractProcessingHandler
|
|||||||
$options['extra']['extra'] = $record['extra'];
|
$options['extra']['extra'] = $record['extra'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($this->release) && !isset($options['release'])) {
|
||||||
|
$options['release'] = $this->release;
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($record['context']['exception']) && $record['context']['exception'] instanceof \Exception) {
|
if (isset($record['context']['exception']) && $record['context']['exception'] instanceof \Exception) {
|
||||||
$options['extra']['message'] = $record['formatted'];
|
$options['extra']['message'] = $record['formatted'];
|
||||||
$this->ravenClient->captureException($record['context']['exception'], $options);
|
$this->ravenClient->captureException($record['context']['exception'], $options);
|
||||||
@@ -208,4 +218,14 @@ class RavenHandler extends AbstractProcessingHandler
|
|||||||
{
|
{
|
||||||
return array('checksum', 'release');
|
return array('checksum', 'release');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $value
|
||||||
|
*/
|
||||||
|
public function setRelease($value)
|
||||||
|
{
|
||||||
|
$this->release = $value;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -204,6 +204,22 @@ class RavenHandlerTest extends TestCase
|
|||||||
$this->assertSame($formatter, $handler->getBatchFormatter());
|
$this->assertSame($formatter, $handler->getBatchFormatter());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testRelease()
|
||||||
|
{
|
||||||
|
$ravenClient = $this->getRavenClient();
|
||||||
|
$handler = $this->getHandler($ravenClient);
|
||||||
|
$release = 'v42.42.42';
|
||||||
|
$handler->setRelease($release);
|
||||||
|
$record = $this->getRecord(Logger::INFO, 'test');
|
||||||
|
$handler->handle($record);
|
||||||
|
$this->assertEquals($release, $ravenClient->lastData['release']);
|
||||||
|
|
||||||
|
$localRelease = 'v41.41.41';
|
||||||
|
$record = $this->getRecord(Logger::INFO, 'test', array('release' => $localRelease));
|
||||||
|
$handler->handle($record);
|
||||||
|
$this->assertEquals($localRelease, $ravenClient->lastData['release']);
|
||||||
|
}
|
||||||
|
|
||||||
private function methodThatThrowsAnException()
|
private function methodThatThrowsAnException()
|
||||||
{
|
{
|
||||||
throw new \Exception('This is an exception');
|
throw new \Exception('This is an exception');
|
||||||
|
Reference in New Issue
Block a user