Skip to content

Commit

Permalink
TASK: Tweak retrieval of GraylogService in Exception handler
Browse files Browse the repository at this point in the history
  • Loading branch information
bwaidelich committed Apr 25, 2017
1 parent 30629eb commit 046fb71
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions Classes/Error/GraylogExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use Neos\Flow\Annotations as Flow;
use Neos\Flow\Error\ProductionExceptionHandler;
use Neos\Flow\ObjectManagement\DependencyInjection\DependencyProxy;
use Yeebase\Graylog\GraylogService;

/**
Expand All @@ -28,13 +29,8 @@ class GraylogExceptionHandler extends ProductionExceptionHandler
*/
protected function echoExceptionWeb($exception)
{

if ($this->graylogService === null) {
$this->graylogService = new GraylogService();
}

if (isset($this->renderingOptions['logException']) && $this->renderingOptions['logException']) {
$this->graylogService->logException($exception);
$this->getGraylogService()->logException($exception);
}

parent::echoExceptionWeb($exception);
Expand All @@ -46,14 +42,27 @@ protected function echoExceptionWeb($exception)
*/
protected function echoExceptionCli($exception)
{
if ($this->graylogService === null) {
$this->graylogService = new GraylogService();
}

if (isset($this->renderingOptions['logException']) && $this->renderingOptions['logException']) {
$this->graylogService->logException($exception);
$this->getGraylogService()->logException($exception);
}

parent::echoExceptionCli($exception);
}

/**
* Returns an instance of the injected GraylogService (including a fallback to a manually instantiated instance
* if Dependency Injection is not (yet) available)
*
* @return GraylogService
*/
private function getGraylogService()
{
if ($this->graylogService instanceof GraylogService) {
return $this->graylogService;
} elseif ($this->graylogService instanceof DependencyProxy) {
return $this->graylogService->_activateDependency();
} else {
return new GraylogService();
}
}
}

0 comments on commit 046fb71

Please sign in to comment.