From e31b138e2f2f9d61d202c7b5fb4b78c46a13a2d9 Mon Sep 17 00:00:00 2001 From: Damien Alexandre Date: Mon, 22 Sep 2014 11:34:14 +0200 Subject: [PATCH] Set back the logger on Elasticsearch client, not pleased with the format --- .../Provider/SearchEngineServiceProvider.php | 17 +++++++++++++---- .../SearchEngine/SearchEngineOptions.php | 4 ++-- .../vagrant/config/phraseanet/configuration.yml | 2 +- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/Alchemy/Phrasea/Core/Provider/SearchEngineServiceProvider.php b/lib/Alchemy/Phrasea/Core/Provider/SearchEngineServiceProvider.php index c9b305c07f..012a7ee74a 100644 --- a/lib/Alchemy/Phrasea/Core/Provider/SearchEngineServiceProvider.php +++ b/lib/Alchemy/Phrasea/Core/Provider/SearchEngineServiceProvider.php @@ -22,6 +22,8 @@ use Alchemy\Phrasea\SearchEngine\Elastic\Thesaurus; use Alchemy\Phrasea\SearchEngine\Phrasea\PhraseaEngine; use Alchemy\Phrasea\SearchEngine\Phrasea\PhraseaEngineSubscriber; use Elasticsearch\Client; +use Monolog\Handler\RotatingFileHandler; +use Monolog\Logger; use Silex\Application; use Silex\ServiceProviderInterface; @@ -90,12 +92,19 @@ class SearchEngineServiceProvider implements ServiceProviderInterface }); $app['elasticsearch.client'] = $app->share(function($app) { - $options = $app['elasticsearch.options']; - $host = sprintf('%s:%s', $options['host'], $options['port']); + $options = $app['elasticsearch.options']; + $clientParams = ['hosts' => [sprintf('%s:%s', $options['host'], $options['port'])]]; - // TODO (mdarse) Add logging support + // Create file logger for debug + if ($app['debug']) { + $logger = new $app['monolog.logger.class']('search logger'); + $logger->pushHandler(new RotatingFileHandler($app['log.path'].DIRECTORY_SEPARATOR.'elasticsearch.log', 2), Logger::INFO); - return new Client(array('hosts' => array($host))); + $clientParams['logObject'] = $logger; + $clientParams['logging'] = true; + } + + return new Client($clientParams); }); $app['elasticsearch.options'] = $app->share(function($app) { diff --git a/lib/Alchemy/Phrasea/SearchEngine/SearchEngineOptions.php b/lib/Alchemy/Phrasea/SearchEngine/SearchEngineOptions.php index 6eb35d69b7..73aebee6cc 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/SearchEngineOptions.php +++ b/lib/Alchemy/Phrasea/SearchEngine/SearchEngineOptions.php @@ -63,13 +63,13 @@ class SearchEngineOptions /** * - * @var DateTime + * @var \DateTime */ protected $date_min; /** * - * @var DateTime + * @var \DateTime */ protected $date_max; diff --git a/resources/vagrant/config/phraseanet/configuration.yml b/resources/vagrant/config/phraseanet/configuration.yml index 826d002bb1..45f848e3e1 100644 --- a/resources/vagrant/config/phraseanet/configuration.yml +++ b/resources/vagrant/config/phraseanet/configuration.yml @@ -24,7 +24,7 @@ main: type: ArrayCache options: [] search-engine: - type: Alchemy\Phrasea\SearchEngine\Phrasea\PhraseaEngine + type: elasticsearch options: [] task-manager: status: started