mirror of
https://github.com/Seldaek/monolog.git
synced 2025-10-22 09:06:10 +02:00
[RavenHandler] Add environment and breadcrumbs support
This commit is contained in:
@@ -38,6 +38,11 @@ class RavenHandler extends AbstractProcessingHandler
|
||||
Logger::EMERGENCY => Raven_Client::FATAL,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var string the current application environment (staging|preprod|prod)
|
||||
*/
|
||||
private $environment;
|
||||
|
||||
/**
|
||||
* @var string should represent the current version of the calling
|
||||
* software. Can be any string (git commit, version number)
|
||||
@@ -109,17 +114,15 @@ class RavenHandler extends AbstractProcessingHandler
|
||||
*
|
||||
* @param FormatterInterface $formatter
|
||||
*/
|
||||
public function setBatchFormatter(FormatterInterface $formatter)
|
||||
public function setBatchFormatter(FormatterInterface $formatter): void
|
||||
{
|
||||
$this->batchFormatter = $formatter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the formatter for the logs generated by handleBatch().
|
||||
*
|
||||
* @return FormatterInterface
|
||||
*/
|
||||
public function getBatchFormatter()
|
||||
public function getBatchFormatter(): FormatterInterface
|
||||
{
|
||||
if (!$this->batchFormatter) {
|
||||
$this->batchFormatter = $this->getDefaultBatchFormatter();
|
||||
@@ -177,6 +180,10 @@ class RavenHandler extends AbstractProcessingHandler
|
||||
$options['extra']['extra'] = $record['extra'];
|
||||
}
|
||||
|
||||
if (!empty($this->environment) && !isset($options['environment'])) {
|
||||
$options['environment'] = $this->environment;
|
||||
}
|
||||
|
||||
if (!empty($this->release) && !isset($options['release'])) {
|
||||
$options['release'] = $this->release;
|
||||
}
|
||||
@@ -190,7 +197,7 @@ class RavenHandler extends AbstractProcessingHandler
|
||||
|
||||
// restore the user context if it was modified
|
||||
if (!is_bool($previousUserContext)) {
|
||||
$this->ravenClient->user_context($previousUserContext);
|
||||
$this->ravenClient->user_context($previousUserContext, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,7 +214,7 @@ class RavenHandler extends AbstractProcessingHandler
|
||||
*
|
||||
* @return FormatterInterface
|
||||
*/
|
||||
protected function getDefaultBatchFormatter()
|
||||
protected function getDefaultBatchFormatter(): FormatterInterface
|
||||
{
|
||||
return new LineFormatter();
|
||||
}
|
||||
@@ -217,19 +224,39 @@ class RavenHandler extends AbstractProcessingHandler
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getExtraParameters()
|
||||
protected function getExtraParameters(): array
|
||||
{
|
||||
return ['checksum', 'release', 'event_id'];
|
||||
return ['checksum', 'release', 'environment', 'event_id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
* @return self
|
||||
*/
|
||||
public function setRelease($value)
|
||||
public function setRelease($value): self
|
||||
{
|
||||
$this->release = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setEnvironment($value): self
|
||||
{
|
||||
$this->environment = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @link https://docs.sentry.io/learn/breadcrumbs/
|
||||
*/
|
||||
public function addBreadcrumb(array $crumb): void
|
||||
{
|
||||
$this->ravenClient->breadcrumbs->record($crumb);
|
||||
}
|
||||
|
||||
public function resetBreadcrumbs(): void
|
||||
{
|
||||
$this->ravenClient->breadcrumbs->reset();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user