Repository: symfony/monolog-bundle (php)

Issue:
Autoconfigure resettable processors with the kernel.reset tag
Hi,

As of writing this, handlers implementing the monolog `ResettableInterface` are correctly configured with the Symfony `kernel.reset` service tag.

See here:
https://github.com/symfony/monolog-bundle/blob/72e798ccdcfd277a6bc88e934b43f618732e3561/DependencyInjection/MonologExtension.php#L881-L883

I suggest we should do the same thing for processors implementing the monolog `ResettableInterface`.

It could be handy for the auto-configuration of the `UidProcessor` for instance: https://github.com/Seldaek/monolog/blob/master/src/Monolog/Processor/UidProcessor.php

If it is something that you would be interested in I could write a PR, I'm just asking for your opinion about that idea first :)

Thank you!

Pull request:
Autoconfigure resettable processors with the kernel.reset tag
fixed #361 for more details.

### TODO

- [x] add the `kernel.reset` tag to processors implementing the `ResettableInterface`
- [x] add a test in the `MonologExtensionTest` class



Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d603702..502f2cf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 3.6.1 (xxxx-xx-xx)
+
+* Register resettable processors (`ResettableInterface`) for autoconfiguration (tag: `kernel.reset`)
+
 ## 3.6.0 (2020-10-06)
 
 * Added support for Symfony Mailer
diff --git a/DependencyInjection/MonologExtension.php b/DependencyInjection/MonologExtension.php
index 3e24d1f..c9fe0e1 100644
--- a/DependencyInjection/MonologExtension.php
+++ b/DependencyInjection/MonologExtension.php
@@ -150,6 +150,10 @@ class MonologExtension extends Extension
                 $container->registerForAutoconfiguration(WebProcessor::class)
                     ->addTag('monolog.processor');
             }
+            if (interface_exists(ResettableInterface::class)) {
+                $container->registerForAutoconfiguration(ResettableInterface::class)
+                    ->addTag('kernel.reset', ['method' => 'reset']);
+            }
             $container->registerForAutoconfiguration(TokenProcessor::class)
                 ->addTag('monolog.processor');
             if (interface_exists(HttpClientInterface::class)) {


Test patch:
diff --git a/Tests/DependencyInjection/MonologExtensionTest.php b/Tests/DependencyInjection/MonologExtensionTest.php
index d374202..3e1c19b 100644
--- a/Tests/DependencyInjection/MonologExtensionTest.php
+++ b/Tests/DependencyInjection/MonologExtensionTest.php
@@ -14,6 +14,7 @@ namespace Symfony\Bundle\MonologBundle\Tests\DependencyInjection;
 use InvalidArgumentException;
 use Monolog\Handler\RollbarHandler;
 use Monolog\Logger;
+use Monolog\Processor\UidProcessor;
 use Symfony\Bundle\MonologBundle\DependencyInjection\MonologExtension;
 use Symfony\Bundle\MonologBundle\DependencyInjection\Compiler\LoggerChannelPass;
 use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -696,6 +697,24 @@ class MonologExtensionTest extends DependencyInjectionTest
         ];
     }
 
+    public function testProcessorAutoConfiguration()
+    {
+        if (!interface_exists('Monolog\ResettableInterface')) {
+            $this->markTestSkipped('The ResettableInterface is not available.');
+        }
+        $service = new Definition(UidProcessor::class);
+        $service->setAutoconfigured(true);
+        $container = $this->getContainer([], ['processor.uid' => $service]);
+        $this->assertTrue($container->hasDefinition('processor.uid'));
+        $processor = $container->getDefinition('processor.uid');
+        $tags = $processor->getTags();
+        $this->assertArrayHasKey('kernel.reset', $tags);
+        $this->assertIsArray($tags['kernel.reset']);
+        $this->assertCount(1, $tags['kernel.reset']);
+        $this->assertIsArray($tags['kernel.reset'][0]);
+        $this->assertArrayHasKey('method', $tags['kernel.reset'][0]);
+        $this->assertEquals('reset', $tags['kernel.reset'][0]['method']);
+    }
 
     protected function getContainer(array $config = [], array $thirdPartyDefinitions = [])
     {