symfony / monolog-bundle

Symfony Monolog Bundle
symfony.com
MIT License
2.89k stars 232 forks source link

3.6.0 causes issues with Symfony 3.4 and custom log handler services #365

Closed brusch closed 3 years ago

brusch commented 4 years ago

Since 3.6.0 we're encountering the following issue, but only when using with Symfony v3.4.45, with v4.4.15 all is working fine:

Fatal error: Uncaught Symfony\Component\DependencyInjection\Exception\InvalidArgumentException: Unused binding "Symfony\Contracts\HttpClient\HttpClientInterface" in service "instanceof.Monolog\Handler\HandlerInterface.0.Pimcore\Log\Handler\ApplicationLoggerDb". in /home/travis/build/pimcore/pimcore/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/ResolveBindingsPass.php on line 50
Symfony\Component\DependencyInjection\Exception\InvalidArgumentException: Unused binding "Symfony\Contracts\HttpClient\HttpClientInterface" in service "instanceof.Monolog\Handler\HandlerInterface.0.Pimcore\Log\Handler\ApplicationLoggerDb". in /home/travis/build/pimcore/pimcore/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/ResolveBindingsPass.php on line 50

This is the used service definition: https://github.com/pimcore/pimcore/blob/416ed369e071cfab175b33b9a4596c130dbe1a29/bundles/CoreBundle/Resources/config/logging.yml#L33

This all seems to be related with this lines: https://github.com/symfony/monolog-bundle/blob/master/DependencyInjection/MonologExtension.php#L158

But I've currently no idea why this breaks the service definition in Symfony 3.4

nicolas-grekas commented 4 years ago

Bundles should never use bindings, they don't need to (neither any auto-*, nor named arguments ideally). This config should be made plain old config.

@brusch would you like sending a PR to update this?

nicolas-grekas commented 4 years ago

I should read more before commenting... This is a rule for autoconfiguration. It's fine. 3.4 doesn't support bindings in autoconfiguration, that's why I suppose.

nicolas-grekas commented 4 years ago

The bundle should drop support for 3.4 IMHO. It's EOLed in a few weeks anyway.

brusch commented 4 years ago

Thanks a lot for the really fast response 👍 I'd be fine with dropping the support 😊 Alternatively we'd have to check for the auto-config support for bindings there, right?

lyrixx commented 4 years ago

I guess we can close this issue?

jdreesen commented 4 years ago

As far as I understand this bundle should drop the support of Symfony 3.4 first.

ninsuo commented 2 years ago

While migrating a 10 years+ project from Symfony 3 to 4 and bumping monolog, I've got the issue.

If it can help others, I patched it by adding a useless HttpClient in the handler's constructor.

<?php

namespace App\Monolog\Handler;

use App\Component\Monitoring;
use Monolog\Handler\AbstractProcessingHandler;
use Symfony\Contracts\HttpClient\HttpClientInterface;

class MonitoringHandler extends AbstractProcessingHandler
{
    /**
     * @var Monitoring
     */
    private $monitoring;

    public function __construct(Monitoring $monitoring, HttpClientInterface $httpClient)

To be removed soon enough once in Symfony4+ :-)