*/ class ElasticaLogger implements LoggerInterface { 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 * @param array $connection host, port and transport of the query * @param array $query arguments */ public function logQuery($path, $method, $data, $time, $connection = array(), $query = array()) { if ($this->debug) { $this->queries[] = array( 'path' => $path, 'method' => $method, 'data' => $data, 'executionMS' => $time, 'connection' => $connection, 'queryString' => $query, ); } 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; } /** * {@inheritdoc} */ public function emergency($message, array $context = array()) { return $this->logger->emergency($message, $context); } /** * {@inheritdoc} */ public function alert($message, array $context = array()) { return $this->logger->alert($message, $context); } /** * {@inheritdoc} */ public function critical($message, array $context = array()) { return $this->logger->critical($message, $context); } /** * {@inheritdoc} */ public function error($message, array $context = array()) { return $this->logger->error($message, $context); } /** * {@inheritdoc} */ public function warning($message, array $context = array()) { return $this->logger->warning($message, $context); } /** * {@inheritdoc} */ public function notice($message, array $context = array()) { return $this->logger->notice($message, $context); } /** * {@inheritdoc} */ public function info($message, array $context = array()) { return $this->logger->info($message, $context); } /** * {@inheritdoc} */ public function debug($message, array $context = array()) { return $this->logger->debug($message, $context); } /** * {@inheritdoc} */ public function log($level, $message, array $context = array()) { return $this->logger->log($level, $message, $context); } }