Logs the request and response data into database.

@param Event $event The shutdown event
324886
public function shutdown(Event $event)
    {
        $request = $event->getSubject()->request;
        if ('OPTIONS' === $request->getMethod()) {
            return;
        }

        if (!Configure::read('requestLogged') && Configure::read('ApiRequest.log')) {
            if (Configure::read('ApiRequest.logOnlyErrors')) {
                $responseCode = $event->getSubject()->httpStatusCode;
                $logOnlyErrorCodes = Configure::read('ApiRequest.logOnlyErrorCodes');
                if (empty($logOnlyErrorCodes) && $responseCode !== 200) {
                    ApiRequestLogger::log($request, $event->getSubject()->response);
                } elseif (in_array($responseCode, $logOnlyErrorCodes)) {
                    ApiRequestLogger::log($request, $event->getSubject()->response);
                }
            } else {
                ApiRequestLogger::log($request, $event->getSubject()->response);
            }
        }
    }
1300919
public function onKernelResponse(ResponseEvent $event): void
    {
        if (!$this->check($event)) {
            return;
        }

        if ($annotation = $this->getAnnotation($event)) {
            $annotation->setData($this->getAttributes($event));
            $key = $annotation->getKey($event->getRequest()->get(self::ROUTE));
            $cache = $this->getCache($key);
            if (null === $cache) {
                $this->setCache($key, $event->getResponse(), $annotation->getExpires());
            }
        }
    }
933713
public function logPostProcedureEvent(Events\PostProcedureEvent $event)
    {
        $procedure = $event->getProcedure();

        $this->logger->info(sprintf('Finished procedure "%s"', $procedure->getName()));
    }
451714
public function handle(Login $event)
    {
        $user = $event->user;
        if (method_exists($user, 'updateLoginTimestamp')) {
            $user->updateLoginTimestamp();
        }
    }
412138
public function sendEvent(Event $event)
    {
        try {
            $this->eventFactory->addDefaultTagsToEntity($event);
            $this->sendEventThroughSenders($event);
        } catch (\Exception $exception) {
            $this->logException($exception);
        }
    }
811788
public function recordThat(Event $event): void
    {
        $this->eventCollection()->record(EventMessage::create($event));
    }
945759
public function processClose($event)
    {
        $response = new Response();
        $response->opcode = Request::OPCODE_CLOSE;
        return $event->sender->close($response);
    }
1074594
public static function handle(LogoutEvent $event)
    {

        // If there is no user, do nothing.
        if (! $event->user)
            return;

        $event->user->login_history()->save(new UserLoginHistory([
            'source'     => Request::getClientIp(),
            'user_agent' => Request::header('User-Agent'),
            'action'     => 'logout',
        ]));

        $message = 'User logged out from ' . Request::getClientIp();
        event('security.log', [$message, 'authentication']);
    }
968818
public function handleParseDate($event)
    {
        if ($event->getResult() === null) {
            /** @var Date $dateAdapter */
            $dateAdapter = $this->framework->getAdapter(Date::class);
            $event->setResult($dateAdapter->parse($event->getFormat(), $event->getTimestamp()));
        }
    }
824673
public function listener(Event $event)
    {
        error_log(
            $event->context->get(0)->getRequestTarget() . PHP_EOL,
            3,
            RUNTIME_PATH . '/logs/example.log'
        );
    }
1194841
public function addLogRecord($event) {
        /**
         * If logging is enabled
         */
        if ($event->sender->module->enableLog) {

            $userId = \Yii::$app->user->id;
            $order = $event->model;

            $message = "ID: $order->id userId: $userId";

            Yii::info($message, $event->name);
        }
    }
1100231
public function send(Event $event)
    {
        $level = $this->getEventLevel($event);
        $message = $this->getEventMessage($event);
        $tags = $this->getEventTags($event);

        $this->logger->log($level, $message, $tags);
    }
564525
protected function handle(Event $event): void
    {
        $method = 'apply'.ClassName::short($event);

        if (!method_exists($this, $method)) {
            return;
        }

        $this->$method($event);
    }
239683
public function handle(Logout $event)
    {
        if ($event->user) {
            $user = $event->user;
            $ip = $this->request->ip();
            $userAgent = $this->request->userAgent();
            $authenticationLog = $user->authentications()->whereIpAddress($ip)->whereUserAgent($userAgent)->first();

            if (! $authenticationLog) {
                $authenticationLog = new AuthenticationLog([
                    'ip_address' => $ip,
                    'user_agent' => $userAgent,
                ]);
            }

            $authenticationLog->logout_at = Carbon::now();

            $user->authentications()->save($authenticationLog);
        }
    }
864563
public function handle(Login $event)
    {
        $event->user->last_login = date('Y-m-d H:i:s');
        $event->user->save();
    }
1273102
public function beforeDispatch(Event $event)
    {
        $this->_setIdentifier($event->getData('request'));
        $this->_initCache();
        $this->_count = $this->_touch();

        $config = $this->getConfig();

        // client has not exceeded rate limit
        if ($this->_count <= $config['limit']) {
            $this->_setHeaders($event->getData('response'));

            return;
        }

        if (isset($config['message'])) {
            $message = $config['message'];
        } else {
            $message = $config['response']['body'];
        }

        // client has reached rate limit
        $event->stopPropagation();
        $response = new Response([
            'body' => $message,
            'status' => 429,
            'type' => $config['response']['type']
        ]);

        if (is_array($config['response']['headers'])) {
            foreach ($config['response']['headers'] as $name => $value) {
                $response = $response->withHeader($name, $value);
            }
        }

        return $response;
    }
1279659
public function onCommandBeforeSend(Event $event)
    {
        $command = $event['command'];
        if ($operation = $command->getOperation()) {
            if ($operation->getErrorResponses()) {
                $request = $command->getRequest();
                $request->getEventDispatcher()
                    ->addListener('request.complete', $this->getErrorClosure($request, $command, $operation));
            }
        }
    }