Log error in exception handler

This commit is contained in:
Thibaud Fabre
2015-09-22 12:53:56 +02:00
parent 10ca1a87c0
commit 7f97445b51
2 changed files with 22 additions and 0 deletions

View File

@@ -267,6 +267,7 @@ class Application extends SilexApplication
$this['phraseanet.exception_handler'] = $this->share(function ($app) {
$handler = PhraseaExceptionHandler::register($app['debug']);
$handler->setTranslator($app['translator']);
$handler->setLogger($app['monolog']);
return $handler;
});

View File

@@ -11,6 +11,8 @@
namespace Alchemy\Phrasea\Core;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Symfony\Component\Debug\ExceptionHandler as SymfonyExceptionHandler;
use Symfony\Component\Debug\Exception\FlattenException;
use Symfony\Component\HttpFoundation\Request;
@@ -21,6 +23,18 @@ class PhraseaExceptionHandler extends SymfonyExceptionHandler
{
private $translator;
private $logger;
public function __construct()
{
$this->logger = new NullLogger();
}
public function setLogger(LoggerInterface $logger)
{
$this->logger = $logger;
}
public function setTranslator(TranslatorInterface $translator)
{
$this->translator = $translator;
@@ -33,6 +47,13 @@ class PhraseaExceptionHandler extends SymfonyExceptionHandler
public function getContent(FlattenException $exception)
{
if ($exception->getStatusCode() == '500') {
$this->logger->error($exception->getMessage(), [
'code' => $exception->getCode(),
'trace' => $exception->getTrace()
]);
}
switch (true) {
case 404 === $exception->getStatusCode():
if (null !== $this->translator) {