monolog-bundle icon indicating copy to clipboard operation
monolog-bundle copied to clipboard

Log channel default and specific override

Open umulmrum opened this issue 6 months ago • 0 comments

Hi,

I use a service definition config like this one:

return static function (ContainerConfigurator $container) {
    $services = $container->services();
    $services
        ->defaults()
            ->autowire()
            ->autoconfigure()
            ->tag('monolog.logger', ['channel' => 'defaultchannel'])
   ;

   $services
       ->set(\MyService::class)
            ->tag('monolog.logger', ['channel' => 'specificchannel'])
   ;
}

So I'd like to define a default channel in the service defaults, but override this default for some services. But in reality MyService will always use the defaultchannel and never the specificchannel. This is because

  • Symfony adds both tags to MyService, but the one from defaults last deliberately (in AbstractServiceConfigurator)
  • MonologBundle iterates over all tags in order, and modifies services for each iteration, which means that the last tag will win (in LoggerChannelPass)

Now I'm unsure where the problem is located. Is my reasoning about defaults and specific overrides correct? Is this in theory the right way to do (if not, what is a better/working/official solution?)? Or is this a possible improvement for the bundle?

Thank you in advance for insights 🙂

umulmrum avatar May 22 '25 20:05 umulmrum