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

Make the log level of match route log configurable #14747

Closed
tdesvenain opened this issue May 25, 2015 · 4 comments
Closed

Make the log level of match route log configurable #14747

tdesvenain opened this issue May 25, 2015 · 4 comments
Labels

Comments

@tdesvenain
Copy link

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.

@Tobion
Copy link
Member

Tobion commented May 25, 2015

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.

@Tobion Tobion closed this as completed May 25, 2015
@geri777
Copy link

geri777 commented Jan 2, 2020

Some lines of sample code would be appreciated

@xabbuh xabbuh added the Routing label Jan 3, 2020
@jt2k
Copy link
Contributor

jt2k commented Jul 20, 2020

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:

<service id="router_listener" class="Symfony\Component\HttpKernel\EventListener\RouterListener">
<tag name="kernel.event_subscriber" />
<tag name="monolog.logger" channel="request" />
<argument type="service" id="router" />
<argument type="service" id="request_stack" />
<argument type="service" id="router.request_context" on-invalid="ignore" />
<argument type="service" id="logger" on-invalid="ignore" />
<argument>%kernel.project_dir%</argument>
<argument>%kernel.debug%</argument>
</service>

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.

@elnur
Copy link
Contributor

elnur commented Nov 12, 2021

Here's my solution:

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class RouterListenerLoggingSilencerPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container): void
    {
        $definition = $container->getDefinition('router_listener');

        foreach ($definition->getArguments() as $index => $argument) {
            if ('logger' != $argument) {
                continue;
            }

            $definition->replaceArgument($index, null);
        }
    }
}

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

No branches or pull requests

6 participants