mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-10 03:23:19 +00:00
Log error in exception handler
This commit is contained in:
@@ -267,6 +267,7 @@ class Application extends SilexApplication
|
|||||||
$this['phraseanet.exception_handler'] = $this->share(function ($app) {
|
$this['phraseanet.exception_handler'] = $this->share(function ($app) {
|
||||||
$handler = PhraseaExceptionHandler::register($app['debug']);
|
$handler = PhraseaExceptionHandler::register($app['debug']);
|
||||||
$handler->setTranslator($app['translator']);
|
$handler->setTranslator($app['translator']);
|
||||||
|
$handler->setLogger($app['monolog']);
|
||||||
|
|
||||||
return $handler;
|
return $handler;
|
||||||
});
|
});
|
||||||
|
@@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
namespace Alchemy\Phrasea\Core;
|
namespace Alchemy\Phrasea\Core;
|
||||||
|
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Psr\Log\NullLogger;
|
||||||
use Symfony\Component\Debug\ExceptionHandler as SymfonyExceptionHandler;
|
use Symfony\Component\Debug\ExceptionHandler as SymfonyExceptionHandler;
|
||||||
use Symfony\Component\Debug\Exception\FlattenException;
|
use Symfony\Component\Debug\Exception\FlattenException;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
@@ -21,6 +23,18 @@ class PhraseaExceptionHandler extends SymfonyExceptionHandler
|
|||||||
{
|
{
|
||||||
private $translator;
|
private $translator;
|
||||||
|
|
||||||
|
private $logger;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->logger = new NullLogger();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setLogger(LoggerInterface $logger)
|
||||||
|
{
|
||||||
|
$this->logger = $logger;
|
||||||
|
}
|
||||||
|
|
||||||
public function setTranslator(TranslatorInterface $translator)
|
public function setTranslator(TranslatorInterface $translator)
|
||||||
{
|
{
|
||||||
$this->translator = $translator;
|
$this->translator = $translator;
|
||||||
@@ -33,6 +47,13 @@ class PhraseaExceptionHandler extends SymfonyExceptionHandler
|
|||||||
|
|
||||||
public function getContent(FlattenException $exception)
|
public function getContent(FlattenException $exception)
|
||||||
{
|
{
|
||||||
|
if ($exception->getStatusCode() == '500') {
|
||||||
|
$this->logger->error($exception->getMessage(), [
|
||||||
|
'code' => $exception->getCode(),
|
||||||
|
'trace' => $exception->getTrace()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case 404 === $exception->getStatusCode():
|
case 404 === $exception->getStatusCode():
|
||||||
if (null !== $this->translator) {
|
if (null !== $this->translator) {
|
||||||
|
Reference in New Issue
Block a user