Skip to content

Log channel default and specific override #507

@umulmrum

Description

@umulmrum

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 🙂

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions