Jarves\Logger\JarvesHandler::getLogRequest PHP Method

getLogRequest() public method

public getLogRequest ( ) : Jarves\Model\LogRequest
return Jarves\Model\LogRequest
    public function getLogRequest()
    {
        if (!$this->logRequest && $this->pageStack->getRequest()) {
            $this->logRequest = new LogRequest();
            $this->logRequest->setId(md5(mt_rand() . ':' . uniqid()));
            $this->logRequest->setDate(microtime(true));
            $this->logRequest->setIp($this->pageStack->getRequest()->getClientIp());
            $this->logRequest->setPath(substr($this->pageStack->getRequest()->getPathInfo(), 0, 254));
            $this->logRequest->setUsername($this->pageStack->getUser() instanceof UserInterface ? $this->pageStack->getUser()->getUsername() : 'Guest');
        }
        return $this->logRequest;
    }

Usage Example

Example #1
0
 public function onKernelTerminate(PostResponseEvent $event)
 {
     if ($this->container->has('profiler')) {
         /** @var $profiler \Symfony\Component\HttpKernel\Profiler\Profiler */
         $profiler = $this->container->get('profiler');
         if ($profile = $profiler->loadProfileFromResponse($event->getResponse())) {
             $logRequest = $this->jarvesLogHandler->getLogRequest();
             $logRequest->setCounts(json_encode($this->jarvesLogHandler->getCounts()));
             $logRequest->setProfileToken($profile->getToken());
             $logRequest->save();
             return;
         }
     }
     //are there any warnings+?
     if ($this->jarvesLogHandler->getCounts()) {
         $logRequest = $this->jarvesLogHandler->getLogRequest();
         $logRequest->setCounts(json_encode($this->jarvesLogHandler->getCounts()));
         $logRequest->save();
     }
     $this->jarvesLogHandler->resetLogRequest();
 }