Add request information in API logging #374

This commit is contained in:
Kendrick Chan 2020-04-10 21:14:45 +08:00
parent 1e23f0cd55
commit 63bb887370

View file

@ -13,24 +13,29 @@ class LogSubscriber implements EventSubscriberInterface
{
protected $allow;
public function __construct()
{
$this->allow = true;
}
public function onKernelController(ControllerEvent $event)
{
$controller = $event->getController();
$this->allow = false;
// when a controller class defines multiple action methods, the controller
// is returned as [$controllerInstance, 'methodName']
if (is_array($controller))
$controller = $controller[0];
if ($controller instanceof LoggedController)
$this->allow = true;
else
$this->allow = false;
if (!($controller instanceof LoggedController))
return;
$this->allow = true;
$req = $event->getRequest();
$reqdata = [
$req->getPathInfo(),
$req->getMethod(),
$req->query->all(),
$req->request->all(),
];
error_log(print_r($req_data, true));
}
public function onKernelResponse(ResponseEvent $event)