Symfony: Make the log level of match route log configurable

Created on 25 May 2015  路  3Comments  路  Source: symfony/symfony

I think it would be fine if we can set the "Matched route..." log level to DEBUG.
On some projects, INFO may not be the accurate level for this information.

Routing

Most helpful comment

I know this issue is closed and a few years old, but I was looking to accomplish this and thought I would share my solution (application is using framework-bundle 4.4).

You can find the default router_listener service (Symfony\Component\HttpKernel\EventListener\RouterListener) configured here: https://github.com/symfony/symfony/blob/3619661d65711901852c6c2ba0b33c3d273593ca/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml#L108-L117

To override, I converted this definition to YAML and added it to my application's services.yaml file:

services:
    # Override router_listener service defined in vendor/symfony/framework-bundle/Resources/config/routing.xml
    # to suppress logger (definition below is identical except for passing in null for the logger)
    router_listener:
        class: Symfony\Component\HttpKernel\EventListener\RouterListener
        arguments:
            - '@router'
            - '@request_stack'
            - '@?router.request_context'
            - null
            - '%kernel.project_dir%'
            - '%kernel.debug%'

This definition is identical, except that null is passed for the logger. As mentioned above, perhaps a better solution is to implement a custom logger that adjusts the level down, but since the only logging happening in the RouterListener is the info-level match log that I want to suppress, I decided to take the easy way out. Hopefully I won't regret this in the future!

Also, using named arguments might be better/clearer, but my goal was to match the XML configuration as close as possible.

All 3 comments

Just change the injected logger. You can for example use a custom decorator that changes info to debug. There is no point in making such things configurable in the framework itself.

Some lines of sample code would be appreciated

I know this issue is closed and a few years old, but I was looking to accomplish this and thought I would share my solution (application is using framework-bundle 4.4).

You can find the default router_listener service (Symfony\Component\HttpKernel\EventListener\RouterListener) configured here: https://github.com/symfony/symfony/blob/3619661d65711901852c6c2ba0b33c3d273593ca/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml#L108-L117

To override, I converted this definition to YAML and added it to my application's services.yaml file:

services:
    # Override router_listener service defined in vendor/symfony/framework-bundle/Resources/config/routing.xml
    # to suppress logger (definition below is identical except for passing in null for the logger)
    router_listener:
        class: Symfony\Component\HttpKernel\EventListener\RouterListener
        arguments:
            - '@router'
            - '@request_stack'
            - '@?router.request_context'
            - null
            - '%kernel.project_dir%'
            - '%kernel.debug%'

This definition is identical, except that null is passed for the logger. As mentioned above, perhaps a better solution is to implement a custom logger that adjusts the level down, but since the only logging happening in the RouterListener is the info-level match log that I want to suppress, I decided to take the easy way out. Hopefully I won't regret this in the future!

Also, using named arguments might be better/clearer, but my goal was to match the XML configuration as close as possible.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kleijnweb picture kleijnweb  路  3Comments

HappyJiJi picture HappyJiJi  路  3Comments

wouterj picture wouterj  路  3Comments

FRAGnatt picture FRAGnatt  路  3Comments

ghost picture ghost  路  3Comments