From 428a1014ca244c5d864252f44ce336b9a0774452 Mon Sep 17 00:00:00 2001 From: Tim Nagel Date: Sun, 24 Aug 2014 19:53:24 +1000 Subject: [PATCH] Move query logging into its own method --- Elastica/Client.php | 49 +++++++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/Elastica/Client.php b/Elastica/Client.php index 1131ba5..372b395 100644 --- a/Elastica/Client.php +++ b/Elastica/Client.php @@ -30,7 +30,11 @@ class Client extends BaseClient private $stopwatch; /** - * {@inheritdoc} + * @param string $path + * @param string $method + * @param array $data + * @param array $query + * @return \Elastica\Response */ public function request($path, $method = Request::GET, $data = array(), array $query = array()) { @@ -41,20 +45,7 @@ class Client extends BaseClient $start = microtime(true); $response = parent::request($path, $method, $data, $query); - if ($this->_logger and $this->_logger instanceof ElasticaLogger) { - $time = microtime(true) - $start; - - $connection = $this->getLastRequest()->getConnection(); - - $connection_array = array( - 'host' => $connection->getHost(), - 'port' => $connection->getPort(), - 'transport' => $connection->getTransport(), - 'headers' => $connection->hasConfig('headers') ? $connection->getConfig('headers') : array(), - ); - - $this->_logger->logQuery($path, $method, $data, $time, $connection_array, $query); - } + $this->logQuery($path, $method, $data, $query, $start); if ($this->stopwatch) { $this->stopwatch->stop('es_request'); @@ -81,4 +72,32 @@ class Client extends BaseClient { $this->stopwatch = $stopwatch; } + + /** + * Log the query if we have an instance of ElasticaLogger. + * + * @param string $path + * @param string $method + * @param array $data + * @param array $query + * @param int $start + */ + private function logQuery($path, $method, $data, array $query, $start) + { + if (!$this->_logger or !$this->_logger instanceof ElasticaLogger) { + return; + } + + $time = microtime(true) - $start; + $connection = $this->getLastRequest()->getConnection(); + + $connection_array = array( + 'host' => $connection->getHost(), + 'port' => $connection->getPort(), + 'transport' => $connection->getTransport(), + 'headers' => $connection->hasConfig('headers') ? $connection->getConfig('headers') : array(), + ); + + $this->_logger->logQuery($path, $method, $data, $time, $connection_array, $query); + } }