440c36f537
Conflicts: Command/PopulateCommand.php Command/SearchCommand.php DependencyInjection/Configuration.php Doctrine/AbstractElasticaToModelTransformer.php Doctrine/AbstractListener.php Doctrine/MongoDB/ElasticaToModelTransformer.php Doctrine/ORM/ElasticaToModelTransformer.php Doctrine/RepositoryManager.php Finder/TransformedFinder.php Paginator/PaginatorAdapterInterface.php Paginator/RawPaginatorAdapter.php Persister/ObjectPersister.php Propel/ElasticaToModelTransformer.php Subscriber/PaginateElasticaQuerySubscriber.php Tests/DataCollector/ElasticaDataCollectorTest.php Tests/Doctrine/AbstractProviderTest.php Tests/Doctrine/RepositoryManagerTest.php Tests/Manager/RepositoryManagerTest.php Tests/RepositoryTest.php Transformer/ElasticaToModelTransformerCollection.php composer.json
79 lines
1.8 KiB
PHP
79 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace FOS\ElasticaBundle\Logger;
|
|
|
|
use Symfony\Component\HttpKernel\Log\LoggerInterface;
|
|
|
|
/**
|
|
* Logger for the Elastica.
|
|
*
|
|
* The {@link logQuery()} method is configured as the logger callable in the
|
|
* service container.
|
|
*
|
|
* @author Gordon Franke <info@nevalon.de>
|
|
*/
|
|
class ElasticaLogger
|
|
{
|
|
protected $logger;
|
|
protected $queries;
|
|
protected $debug;
|
|
|
|
/**
|
|
* Constructor.
|
|
*
|
|
* @param LoggerInterface|null $logger The Symfony logger
|
|
* @param bool $debug
|
|
*/
|
|
public function __construct(LoggerInterface $logger = null, $debug = false)
|
|
{
|
|
$this->logger = $logger;
|
|
$this->queries = array();
|
|
$this->debug = $debug;
|
|
}
|
|
|
|
/**
|
|
* Logs a query.
|
|
*
|
|
* @param string $path Path to call
|
|
* @param string $method Rest method to use (GET, POST, DELETE, PUT)
|
|
* @param array $data arguments
|
|
* @param float $time execution time
|
|
*/
|
|
public function logQuery($path, $method, $data, $time)
|
|
{
|
|
if ($this->debug) {
|
|
$this->queries[] = array(
|
|
'path' => $path,
|
|
'method' => $method,
|
|
'data' => $data,
|
|
'executionMS' => $time
|
|
);
|
|
}
|
|
|
|
if (null !== $this->logger) {
|
|
$message = sprintf("%s (%s) %0.2f ms", $path, $method, $time * 1000);
|
|
$this->logger->info($message, (array) $data);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Returns the number of queries that have been logged.
|
|
*
|
|
* @return integer The number of queries logged
|
|
*/
|
|
public function getNbQueries()
|
|
{
|
|
return count($this->queries);
|
|
}
|
|
|
|
/**
|
|
* Returns a human-readable array of queries logged.
|
|
*
|
|
* @return array An array of queries
|
|
*/
|
|
public function getQueries()
|
|
{
|
|
return $this->queries;
|
|
}
|
|
}
|