Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
19 changes: 13 additions & 6 deletions src/DependencyInjection/MonologExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand All @@ -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'] = [
Expand Down