@@ -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