简体   繁体   中英

Symfony CMF Dynamic router “was not able to match” logs

I have a Symfony 2.6 application using Symfony CMF routing bundle 1.3 where we use a combination of normal symfony routes and dynamic routes for custom stores (amongst other things, the below example focuses on one of our dynamic routers).

The problem is that we are getting endless logs about the router not being able to match the dynamic routes when they work just fine.

The most common entry being:

Router Symfony\Bundle\FrameworkBundle\Routing\Router was not able to match, message ""

We occasionally see

Router Symfony\Cmf\Bundle\RoutingBundle\Routing\DynamicRouter was not able to match, message ""

Is there a way to disable these logs or change my dynamic router configuration/setup so that these errors only appear when the route actually fails.

Here is my config/setup:

# app/config/config.yml

cmf_routing:
    chain:
        routers_by_id:
            router.default:             32
            cmf_routing.dynamic_router: 30
    dynamic:
        enabled:                      true
        route_provider_service_id:    store_router

And the actual dynamic router based on

// StoreBundle/Router/StoreRouter.php

<?php

/**
 * @DI\Service("store_router")
 */
class StoreRouter implements RouteProviderInterface
{
    protected $em;

    /**
     * @DI\InjectParams({
     *      "em" = @DI\Inject("doctrine.orm.entity_manager")
     * })
     */
    public function __construct(EntityManager $em)
    {
        $this->em = $em;
    }

    /**
     * @param Request $request
     * @return RouteCollection
     */
    public function getRouteCollectionForRequest(Request $request)
    {
        $collection = new RouteCollection();

        $store = $this->em->getRepository('StoreBundle:Store')->findOneBySlug(substr($request->getPathInfo(), 1), $request->get('key', null));

        // no store found, return an empty collection
        if (empty($store)) {
            return $collection;
        }

        $route = new Route(
            '/' . $store->getSlug(),
            [
                '_controller' => 'StoreBundle:Store:view',
                'slug' => $stote->getSlug()
            ]
        );

        $collection->add($store->getSlug(), $route);

        return $collection;
    }

    public function getRouteByName($name, $params = [])
    {
    }

    public function getRoutesByNames($names)
    {
    }
}

If theres a better way to use dynamic routes I'd love to hear it :)

The log entries are created at level "debug". You can set the minimum level of your logger higher. If you need debug logs for other things, you can write a CompilerPass that removes the logger argument on the symfony_cmf.router service.

I agree that it would make sense to have the log level configureable, with a false option to completely disable logging. If you want this, I am happy to review and merge a pull request on the Routing component for the code and the RoutingBundle to expose the configuration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM