Cake\ElasticSearch\Datasource\Connection::_log PHP Method

_log() protected method

Log requests to Elastic Search.
protected _log ( Request | array $context ) : void
$context Elastica\Request | array The context of the request made.
return void
    protected function _log($context)
    {
        if (!$this->logQueries) {
            return;
        }
        if (!isset($this->_logger)) {
            $this->_logger = Log::engine('elasticsearch') ?: new ElasticaLog();
        }
        if ($context instanceof Request) {
            $data = $context->toArray();
        } else {
            $data = ['message' => $context];
        }
        $logData = ['method' => $data['method'], 'path' => $data['path'], 'data' => $data['data']];
        $data = json_encode($logData, JSON_PRETTY_PRINT);
        $loggedQuery = new LoggedQuery();
        $loggedQuery->query = $data;
        if ($this->_logger instanceof \Psr\Log\LoggerInterface) {
            $this->_logger->log('debug', $loggedQuery);
        } else {
            $this->_logger->log($loggedQuery);
        }
    }