Skip to content

Commit faf6943

Browse files
committed
Use an HttpClient without logger in all handlers
1 parent dd80460 commit faf6943

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

DependencyInjection/MonologExtension.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,21 @@
1313

1414
use Monolog\Logger;
1515
use Monolog\Processor\ProcessorInterface;
16+
use Monolog\Handler\HandlerInterface;
1617
use Monolog\ResettableInterface;
1718
use Symfony\Bridge\Monolog\Handler\FingersCrossed\HttpCodeActivationStrategy;
1819
use Symfony\Bridge\Monolog\Processor\TokenProcessor;
1920
use Symfony\Bridge\Monolog\Processor\WebProcessor;
2021
use Symfony\Bundle\FullStack;
21-
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
22-
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
23-
use Symfony\Component\DependencyInjection\ContainerBuilder;
2422
use Symfony\Component\Config\FileLocator;
23+
use Symfony\Component\DependencyInjection\Argument\BoundArgument;
24+
use Symfony\Component\DependencyInjection\ContainerBuilder;
2525
use Symfony\Component\DependencyInjection\Definition;
26+
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
2627
use Symfony\Component\DependencyInjection\Reference;
28+
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
2729
use Symfony\Component\HttpKernel\Kernel;
30+
use Symfony\Contracts\HttpClient\HttpClientInterface;
2831

2932
/**
3033
* MonologExtension is an extension for the Monolog library.
@@ -126,6 +129,12 @@ public function load(array $configs, ContainerBuilder $container)
126129
}
127130
$container->registerForAutoconfiguration(TokenProcessor::class)
128131
->addTag('monolog.processor');
132+
if (interface_exists(HttpClientInterface::class)) {
133+
$handlerAutoconfiguration = $container->registerForAutoconfiguration(HandlerInterface::class);
134+
$handlerAutoconfiguration->setBindings($handlerAutoconfiguration->getBindings() + [
135+
HttpClientInterface::class => new BoundArgument(new Reference('monolog.http_client'), false),
136+
]);
137+
}
129138
}
130139
}
131140

Resources/config/monolog.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,9 @@
3636
<service id="monolog.formatter.logstash" class="Monolog\Formatter\LogstashFormatter" public="false">
3737
<argument index="0">app</argument>
3838
</service>
39+
40+
<service id="monolog.http_client" class="Symfony\Contracts\HttpClient\HttpClientInterface" public="false">
41+
<factory class="Symfony\Component\HttpClient\HttpClient" method="create" />
42+
</service>
3943
</services>
4044
</container>

0 commit comments

Comments
 (0)