Skip to content

Commit

Permalink
Add setLogErrorRenderer() to ErrorHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanNerd committed Aug 13, 2019
1 parent ed5ecf2 commit 319a8c6
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Slim/Handlers/ErrorHandler.php
Expand Up @@ -53,6 +53,11 @@ class ErrorHandler implements ErrorHandlerInterface
'text/plain' => PlainTextErrorRenderer::class,
];

/**
* @var ErrorRendererInterface|string|callable
*/
protected $logErrorRenderer = PlainTextErrorRenderer::class;

/**
* @var bool
*/
Expand Down Expand Up @@ -259,14 +264,25 @@ public function setDefaultErrorRenderer(string $contentType, $errorRenderer): vo
$this->defaultErrorRenderer = $errorRenderer;
}

/**
* Set the renderer for the error logger
*
* @param ErrorRendererInterface|string|callable $logErrorRenderer
*/
public function setLogErrorRenderer($logErrorRenderer): void
{
$this->logErrorRenderer = $logErrorRenderer;
}

/**
* Write to the error log if $logErrors has been set to true
*
* @return void
*/
protected function writeToErrorLog(): void
{
$renderer = new PlainTextErrorRenderer();
/** @var ErrorRendererInterface $renderer */
$renderer = $this->callableResolver->resolve($this->logErrorRenderer);
$error = $renderer->__invoke($this->exception, $this->logErrorDetails);
$error .= "\nView in rendered output by enabling the \"displayErrorDetails\" setting.\n";
$this->logError($error);
Expand Down

0 comments on commit 319a8c6

Please sign in to comment.