Skip to content

Commit 2e400b5

Browse files
committed
[Monolog] Use a standalone http client for ElasticsearchLogstashHandler
This mean the logger will not be injected in this Handler, and it will prevent an infinite loop : a log > ElasticsearchLogstashHandler > fire an HTTP request > the http request emits another log > ...
1 parent 7ed6d35 commit 2e400b5

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Psr\EventDispatcher\EventDispatcherInterface as PsrEventDispatcherInterface;
2020
use Psr\Http\Client\ClientInterface;
2121
use Psr\Log\LoggerAwareInterface;
22+
use Symfony\Bridge\Monolog\Handler\ElasticsearchLogstashHandler;
2223
use Symfony\Bridge\Monolog\Processor\DebugProcessor;
2324
use Symfony\Bridge\Twig\Extension\CsrfExtension;
2425
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@@ -38,11 +39,12 @@
3839
use Symfony\Component\Cache\ResettableInterface;
3940
use Symfony\Component\Config\FileLocator;
4041
use Symfony\Component\Config\Loader\LoaderInterface;
41-
use Symfony\Component\Config\Resource\DirectoryResource;
4242
use Symfony\Component\Config\ResourceCheckerInterface;
43+
use Symfony\Component\Config\Resource\DirectoryResource;
4344
use Symfony\Component\Console\Application;
4445
use Symfony\Component\Console\Command\Command;
4546
use Symfony\Component\DependencyInjection\Alias;
47+
use Symfony\Component\DependencyInjection\Argument\BoundArgument;
4648
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
4749
use Symfony\Component\DependencyInjection\ChildDefinition;
4850
use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
@@ -75,8 +77,8 @@
7577
use Symfony\Component\Lock\LockFactory;
7678
use Symfony\Component\Lock\LockInterface;
7779
use Symfony\Component\Lock\PersistingStoreInterface;
78-
use Symfony\Component\Lock\Store\StoreFactory;
7980
use Symfony\Component\Lock\StoreInterface;
81+
use Symfony\Component\Lock\Store\StoreFactory;
8082
use Symfony\Component\Mailer\Bridge\Amazon\Transport\SesTransportFactory;
8183
use Symfony\Component\Mailer\Bridge\Google\Transport\GmailTransportFactory;
8284
use Symfony\Component\Mailer\Bridge\Mailchimp\Transport\MandrillTransportFactory;
@@ -446,6 +448,11 @@ public function load(array $configs, ContainerBuilder $container)
446448
$container->registerForAutoconfiguration(LoggerAwareInterface::class)
447449
->addMethodCall('setLogger', [new Reference('logger')]);
448450

451+
$handlerAutoconfiguration = $container->registerForAutoconfiguration(ElasticsearchLogstashHandler::class);
452+
$handlerAutoconfiguration->setBindings($handlerAutoconfiguration->getBindings() + [
453+
HttpClientInterface::class => new BoundArgument(new Reference('monolog.http_client'), false),
454+
]);
455+
449456
if (!$container->getParameter('kernel.debug')) {
450457
// remove tagged iterator argument for resource checkers
451458
$container->getDefinition('config_cache_factory')->setArguments([]);

src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,5 +127,9 @@
127127
<argument type="service" id="service_container" />
128128
<argument type="tagged_iterator" tag="container.env_var_loader" />
129129
</service>
130+
131+
<service id="monolog.http_client" class="Symfony\Contracts\HttpClient\HttpClientInterface">
132+
<factory class="Symfony\Component\HttpClient\HttpClient" method="create" />
133+
</service>
130134
</services>
131135
</container>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy