mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-24 02:13:15 +00:00
Merge pull request #1516 from aztech-dev/logging-api
Enable application logging from API calls
This commit is contained in:
@@ -41,7 +41,10 @@ return call_user_func(function ($environment = PhraseaApplication::ENV_PROD) {
|
|||||||
$app->loadPlugins();
|
$app->loadPlugins();
|
||||||
|
|
||||||
$app['exception_handler'] = $app->share(function ($app) {
|
$app['exception_handler'] = $app->share(function ($app) {
|
||||||
return new ApiExceptionHandlerSubscriber($app);
|
$handler = new ApiExceptionHandlerSubscriber($app);
|
||||||
|
$handler->setLogger($app['monolog']);
|
||||||
|
|
||||||
|
return $handler;
|
||||||
});
|
});
|
||||||
$app['monolog'] = $app->share($app->extend('monolog', function (Logger $monolog) {
|
$app['monolog'] = $app->share($app->extend('monolog', function (Logger $monolog) {
|
||||||
$monolog->pushProcessor(new WebProcessor());
|
$monolog->pushProcessor(new WebProcessor());
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ namespace Alchemy\Phrasea\Core\Event\Subscriber;
|
|||||||
|
|
||||||
use Alchemy\Phrasea\Application;
|
use Alchemy\Phrasea\Application;
|
||||||
use Alchemy\Phrasea\Controller\Api\Result;
|
use Alchemy\Phrasea\Controller\Api\Result;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Psr\Log\NullLogger;
|
||||||
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
|
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
|
||||||
use Symfony\Component\HttpKernel\KernelEvents;
|
use Symfony\Component\HttpKernel\KernelEvents;
|
||||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
@@ -27,9 +29,17 @@ class ApiExceptionHandlerSubscriber implements EventSubscriberInterface
|
|||||||
{
|
{
|
||||||
private $app;
|
private $app;
|
||||||
|
|
||||||
|
private $logger;
|
||||||
|
|
||||||
public function __construct(Application $app)
|
public function __construct(Application $app)
|
||||||
{
|
{
|
||||||
$this->app = $app;
|
$this->app = $app;
|
||||||
|
$this->logger = new NullLogger();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setLogger(LoggerInterface $logger)
|
||||||
|
{
|
||||||
|
$this->logger = $logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getSubscribedEvents()
|
public static function getSubscribedEvents()
|
||||||
@@ -64,6 +74,13 @@ class ApiExceptionHandlerSubscriber implements EventSubscriberInterface
|
|||||||
$code = 500;
|
$code = 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($code == 500) {
|
||||||
|
$this->logger->error($e->getMessage(), [
|
||||||
|
'code' => $e->getCode(),
|
||||||
|
'trace' => $e->getTrace()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
if ($e instanceof HttpExceptionInterface) {
|
if ($e instanceof HttpExceptionInterface) {
|
||||||
$headers = $e->getHeaders();
|
$headers = $e->getHeaders();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user