Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage of logger within the bundle #197

Closed
nickbr-icapps opened this issue Jan 17, 2024 · 2 comments
Closed

Usage of logger within the bundle #197

nickbr-icapps opened this issue Jan 17, 2024 · 2 comments

Comments

@nickbr-icapps
Copy link

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!

@Seldaek
Copy link
Member

Seldaek commented Jan 18, 2024

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

@nickbr-icapps
Copy link
Author

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();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants