@@ -305,38 +305,50 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
305
305
break ;
306
306
307
307
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 ' :
308
313
if (isset ($ handler ['elasticsearch ' ]['id ' ])) {
309
- $ elasticaClient = new Reference ($ handler ['elasticsearch ' ]['id ' ]);
314
+ $ client = new Reference ($ handler ['elasticsearch ' ]['id ' ]);
310
315
} 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
+ }
328
340
}
329
341
330
- $ elasticaClient ->setArguments ([
331
- $ elasticaClientArguments
342
+ $ client ->setArguments ([
343
+ $ clientArguments
332
344
]);
333
345
334
- $ elasticaClient ->setPublic (false );
346
+ $ client ->setPublic (false );
335
347
}
336
348
337
349
// elastica handler definition
338
350
$ definition ->setArguments ([
339
- $ elasticaClient ,
351
+ $ client ,
340
352
[
341
353
'index ' => $ handler ['index ' ],
342
354
'type ' => $ handler ['document_type ' ],
@@ -1021,7 +1033,9 @@ private function getHandlerClassByType($handlerType)
1021
1033
];
1022
1034
1023
1035
$ v2HandlerTypesAdded = [
1036
+ 'elastica ' => 'Monolog\Handler\ElasticaHandler ' ,
1024
1037
'elasticsearch ' => 'Monolog\Handler\ElasticaHandler ' ,
1038
+ 'elastic_search ' => 'Monolog\Handler\ElasticsearchHandler ' ,
1025
1039
'fallbackgroup ' => 'Monolog\Handler\FallbackGroupHandler ' ,
1026
1040
'noop ' => 'Monolog\Handler\NoopHandler ' ,
1027
1041
];
0 commit comments