Skip to content

Commit f5b44f1

Browse files
authored
Deprecate elasticsearch type, and split it into elastica and elastic_search types (#438)
1 parent 8aef721 commit f5b44f1

File tree

2 files changed

+51
-26
lines changed

2 files changed

+51
-26
lines changed

DependencyInjection/Configuration.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,18 @@
8181
* - [level]: level name or int value, defaults to DEBUG
8282
* - [bubble]: bool, defaults to true
8383
*
84-
* - elasticsearch:
84+
* - elastic_search:
85+
* - elasticsearch:
86+
* - id: optional if host is given
87+
* - host: elastic search host name, with scheme (e.g. "https://127.0.0.1:9200")
88+
* - [user]: elastic search user name
89+
* - [password]: elastic search user password
90+
* - [index]: index name, defaults to monolog
91+
* - [document_type]: document_type, defaults to logs
92+
* - [level]: level name or int value, defaults to DEBUG
93+
* - [bubble]: bool, defaults to true
94+
*
95+
* - elastica:
8596
* - elasticsearch:
8697
* - id: optional if host is given
8798
* - host: elastic search host name. Do not prepend with http(s)://
@@ -878,9 +889,9 @@ private function addElasticsearchSection(ArrayNodeDefinition $handerNode)
878889
->thenInvalid('What must be set is either the host or the id.')
879890
->end()
880891
->end()
881-
->scalarNode('index')->defaultValue('monolog')->end() // elasticsearch
882-
->scalarNode('document_type')->defaultValue('logs')->end() // elasticsearch
883-
->scalarNode('ignore_error')->defaultValue(false)->end() // elasticsearch
892+
->scalarNode('index')->defaultValue('monolog')->end() // elasticsearch & elastic_search & elastica
893+
->scalarNode('document_type')->defaultValue('logs')->end() // elasticsearch & elastic_search & elastica
894+
->scalarNode('ignore_error')->defaultValue(false)->end() // elasticsearch & elastic_search & elastica
884895
->end()
885896
;
886897
}

DependencyInjection/MonologExtension.php

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -305,38 +305,50 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
305305
break;
306306

307307
case 'elasticsearch':
308+
@trigger_error('The "elasticsearch" handler type is deprecated in MonologBundle since version 3.8.0, use the "elastica" type instead, or switch to the official Elastic client using the "elastic_search" type.', E_USER_DEPRECATED);
309+
// no break
310+
311+
case 'elastica':
312+
case 'elastic_search':
308313
if (isset($handler['elasticsearch']['id'])) {
309-
$elasticaClient = new Reference($handler['elasticsearch']['id']);
314+
$client = new Reference($handler['elasticsearch']['id']);
310315
} else {
311-
// elastica client new definition
312-
$elasticaClient = new Definition('Elastica\Client');
313-
$elasticaClientArguments = [
314-
'host' => $handler['elasticsearch']['host'],
315-
'port' => $handler['elasticsearch']['port'],
316-
'transport' => $handler['elasticsearch']['transport'],
317-
];
318-
319-
if (isset($handler['elasticsearch']['user'], $handler['elasticsearch']['password'])) {
320-
$elasticaClientArguments = array_merge(
321-
$elasticaClientArguments,
322-
[
323-
'headers' => [
324-
'Authorization' => 'Basic ' . base64_encode($handler['elasticsearch']['user'] . ':' . $handler['elasticsearch']['password'])
325-
]
326-
]
327-
);
316+
if ($handler['type'] === 'elastic_search') {
317+
// v8 has a new Elastic\ prefix
318+
$client = new Definition(class_exists('Elastic\Elasticsearch\Client') ? 'Elastic\Elasticsearch\Client' : 'Elasticsearch\Client');
319+
$clientArguments = [
320+
'host' => $handler['elasticsearch']['host'],
321+
];
322+
323+
if (isset($handler['elasticsearch']['user'], $handler['elasticsearch']['password'])) {
324+
$clientArguments['basicAuthentication'] = [$handler['elasticsearch']['user'], $handler['elasticsearch']['password']];
325+
}
326+
} else {
327+
$client = new Definition('Elastica\Client');
328+
329+
$clientArguments = [
330+
'host' => $handler['elasticsearch']['host'],
331+
'port' => $handler['elasticsearch']['port'],
332+
'transport' => $handler['elasticsearch']['transport'],
333+
];
334+
335+
if (isset($handler['elasticsearch']['user'], $handler['elasticsearch']['password'])) {
336+
$clientArguments['headers'] = [
337+
'Authorization' => 'Basic ' . base64_encode($handler['elasticsearch']['user'] . ':' . $handler['elasticsearch']['password'])
338+
];
339+
}
328340
}
329341

330-
$elasticaClient->setArguments([
331-
$elasticaClientArguments
342+
$client->setArguments([
343+
$clientArguments
332344
]);
333345

334-
$elasticaClient->setPublic(false);
346+
$client->setPublic(false);
335347
}
336348

337349
// elastica handler definition
338350
$definition->setArguments([
339-
$elasticaClient,
351+
$client,
340352
[
341353
'index' => $handler['index'],
342354
'type' => $handler['document_type'],
@@ -1021,7 +1033,9 @@ private function getHandlerClassByType($handlerType)
10211033
];
10221034

10231035
$v2HandlerTypesAdded = [
1036+
'elastica' => 'Monolog\Handler\ElasticaHandler',
10241037
'elasticsearch' => 'Monolog\Handler\ElasticaHandler',
1038+
'elastic_search' => 'Monolog\Handler\ElasticsearchHandler',
10251039
'fallbackgroup' => 'Monolog\Handler\FallbackGroupHandler',
10261040
'noop' => 'Monolog\Handler\NoopHandler',
10271041
];

0 commit comments

Comments
 (0)