Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.x - Add setLogErrorRenderer() to ErrorHandler #2801

Merged
merged 8 commits into from
Aug 18, 2019
18 changes: 17 additions & 1 deletion Slim/Handlers/ErrorHandler.php
Original file line number Diff line number Diff line change
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);
l0gicgate marked this conversation as resolved.
Show resolved Hide resolved
$error .= "\nView in rendered output by enabling the \"displayErrorDetails\" setting.\n";
$this->logError($error);
Expand Down