简体   繁体   中英

Doctrine MongoDB disable logger on fixture load

Is there a way to disable Doctrine MongoDB bundle logger on fixture load only? like suggested in https://stackoverflow.com/a/35222045/3965970 but for MongoDB bundle.

Thanks

Yes, absolutely the same way, call $manager->getConnection()->getConfiguration()->setLoggerCallable(null); right in the fixture.

Unfortunately in Doctrine MongoODM-bundle version 4.0 and higher this approach no longer works.

The easiest way is to disable logging in the configuration, see https://symfony.com/doc/master/bundles/DoctrineMongoDBBundle/config.html

You can also disable the logger manually, but you'll need doctrine_mongodb.odm.command_logger service.

What I did in my Symfony 4 application is to create an alias to enable proper dependency injection and then unregister the listener:

services.yaml

Doctrine\Bundle\MongoDBBundle\APM\PSRCommandLogger:
    alias: "doctrine_mongodb.odm.command_logger"

some constructor of a Command or Service:

public function __construct(PSRCommandLogger $mongoLogger)
{
    $mongoLogger->unregister();
}

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