diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index ac9d0897..a66d320e 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -908,6 +908,7 @@ private function addElasticsearchSection(ArrayNodeDefinition $handlerNode) ->end() ->children() ->scalarNode('id')->end() + ->arrayNode('hosts')->prototype('scalar')->end()->end() ->scalarNode('host')->end() ->scalarNode('port')->defaultValue(9200)->end() ->scalarNode('transport')->defaultValue('Http')->end() @@ -916,7 +917,7 @@ private function addElasticsearchSection(ArrayNodeDefinition $handlerNode) ->end() ->validate() ->ifTrue(function ($v) { - return !isset($v['id']) && !isset($v['host']); + return !isset($v['id']) && !isset($v['host']) && !isset($v['hosts']); }) ->thenInvalid('What must be set is either the host or the id.') ->end() diff --git a/src/DependencyInjection/MonologExtension.php b/src/DependencyInjection/MonologExtension.php index e6629142..dc28eb6f 100644 --- a/src/DependencyInjection/MonologExtension.php +++ b/src/DependencyInjection/MonologExtension.php @@ -304,7 +304,7 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler $factory = class_exists('Elastic\Elasticsearch\ClientBuilder') ? 'Elastic\Elasticsearch\ClientBuilder' : 'Elasticsearch\ClientBuilder'; $client->setFactory([$factory, 'fromConfig']); $clientArguments = [ - 'hosts' => [$handler['elasticsearch']['host']], + 'hosts' => $handler['elasticsearch']['hosts'] ?? [$handler['elasticsearch']['host']], ]; if (isset($handler['elasticsearch']['user'], $handler['elasticsearch']['password'])) { @@ -313,11 +313,18 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler } else { $client = new Definition('Elastica\Client'); - $clientArguments = [ - 'host' => $handler['elasticsearch']['host'], - 'port' => $handler['elasticsearch']['port'], - 'transport' => $handler['elasticsearch']['transport'], - ]; + if (isset($handler['elasticsearch']['hosts'])) { + $clientArguments = [ + 'hosts' => $handler['elasticsearch']['hosts'], + 'transport' => $handler['elasticsearch']['transport'], + ]; + } else { + $clientArguments = [ + 'host' => $handler['elasticsearch']['host'], + 'port' => $handler['elasticsearch']['port'], + 'transport' => $handler['elasticsearch']['transport'], + ]; + } if (isset($handler['elasticsearch']['user'], $handler['elasticsearch']['password'])) { $clientArguments['headers'] = [