diff --git a/Client.php b/Client.php index 8430b36..8c9be1a 100644 --- a/Client.php +++ b/Client.php @@ -4,6 +4,8 @@ namespace FOS\ElasticaBundle; use Elastica\Client as ElasticaClient; use Elastica\Request; +use Elastica\Transport\Http; +use Elastica\Transport\Https; /** * @author Gordon Franke @@ -17,7 +19,16 @@ class Client extends ElasticaClient if (null !== $this->_logger) { $time = microtime(true) - $start; - $this->_logger->logQuery($path, $method, $data, $time); + + $connection = $this->getLastRequest()->getConnection(); + $transport = $connection->getTransportObject(); + $full_host = null; + + if ($transport instanceof Http || $transport instanceof Https) { + $full_host = $connection->getTransport().'://'.$connection->getHost().':'.$connection->getPort(); + } + + $this->_logger->logQuery($path, $method, $data, $time, $full_host); } return $response; diff --git a/Logger/ElasticaLogger.php b/Logger/ElasticaLogger.php index 1705d06..2d8d0ae 100644 --- a/Logger/ElasticaLogger.php +++ b/Logger/ElasticaLogger.php @@ -38,15 +38,17 @@ class ElasticaLogger implements LoggerInterface * @param string $method Rest method to use (GET, POST, DELETE, PUT) * @param array $data arguments * @param float $time execution time + * @param string $full_host host and port of the query */ - public function logQuery($path, $method, $data, $time) + public function logQuery($path, $method, $data, $time, $full_host = null) { if ($this->debug) { $this->queries[] = array( 'path' => $path, 'method' => $method, 'data' => $data, - 'executionMS' => $time + 'executionMS' => $time, + 'full_host' => $full_host ); } diff --git a/Resources/views/Collector/elastica.html.twig b/Resources/views/Collector/elastica.html.twig index bfbd31a..8b27376 100644 --- a/Resources/views/Collector/elastica.html.twig +++ b/Resources/views/Collector/elastica.html.twig @@ -52,15 +52,17 @@ Time: {{ '%0.2f'|format(query.executionMS * 1000) }} ms - - + - - - Display cURL query - + {% if query.full_host %} + + + + - + Display cURL query + - + + {% endif %} {% endfor %} @@ -79,7 +81,6 @@ } else { sections[0].style.display = 'inline'; sections[1].style.display = 'none'; - //sections[3].style.display = 'none'; document.getElementById(link.hash.replace("#", "")).style.display = 'none'; } diff --git a/Tests/Logger/ElasticaLoggerTest.php b/Tests/Logger/ElasticaLoggerTest.php index 3cf6d2d..73ba4ac 100644 --- a/Tests/Logger/ElasticaLoggerTest.php +++ b/Tests/Logger/ElasticaLoggerTest.php @@ -9,7 +9,6 @@ use FOS\ElasticaBundle\Logger\ElasticaLogger; */ class ElasticaLoggerTest extends \PHPUnit_Framework_TestCase { - public function testGetZeroIfNoQueriesAdded() { $elasticaLogger = new ElasticaLogger; @@ -36,15 +35,17 @@ class ElasticaLoggerTest extends \PHPUnit_Framework_TestCase $method = 'testMethod'; $data = array('data'); $time = 12; + $full_host = 'http://example.com:9200'; $expected = array( 'path' => $path, 'method' => $method, 'data' => $data, - 'executionMS' => $time + 'executionMS' => $time, + 'full_host' => $full_host, ); - $elasticaLogger->logQuery($path, $method, $data, $time); + $elasticaLogger->logQuery($path, $method, $data, $time, $full_host); $returnedQueries = $elasticaLogger->getQueries(); $this->assertEquals($expected, $returnedQueries[0]); }