nelmio/NelmioCorsBundle

Usage of logger within the bundle

nickbr-icapps opened this issue · 2 comments

Hi,

I'm trying to use our logger (monolog) within the bundle, but it seems it is not automatically passed into the constructor of CorsListener.
Is there any property we need to set in the configuration of the bundle?

We are using version 2.4 of this bundle and symfony 6.3

Thanks!

I think you'd have to redefine the listener service in your own services.yaml or equivalent, adding the logger argument:

https://github.com/nelmio/NelmioCorsBundle/blob/master/Resources/config/services.xml#L14C1-L18C19

We have managed to fix it by adding this in our own service file:

$services->set('nelmio_cors.cors_listener')
        ->class(Nelmio\CorsBundle\EventListener\CorsListener::class)
        ->arg('$configurationResolver', service('nelmio_cors.options_resolver'))
        ->arg('$logger', service(Psr\Log\LoggerInterface::class))
        ->tag('kernel.event_listener', ['event' => Symfony\Component\HttpKernel\Event\RequestEvent::class, 'method' => 'onKernelRequest', 'priority' => 250])
        ->tag('kernel.event_listener', ['event' => Symfony\Component\HttpKernel\Event\ResponseEvent::class, 'method' => 'onKernelResponse', 'priority' => 0])
        ->public();