How to turn on logging (profiling) using ZF2 Doctrine MongoDb module

1.1k Views Asked by At

I've successfully integrated Doctrine MongoDB module in Zend Framework 2 and now I need to keep track of each query to MongoDB. Does anybody know how to turn on logging?

2

There are 2 best solutions below

0
On BEST ANSWER

I just proposed a pull request on the DoctrineMongoODMModule to integrate the logging configuration option of MongoDB ODM. Hopefully it'll be merged soon.

You will then only have to add this in the doctrine-mongo-odm.global.php file :

'doctrine' => array(
    // [...]
    'configuration' => array(
        'odm_default' => array(
            // [...]
            'logger_callable'    => function(array $log, \Zend\ServiceManager\ServiceLocatorInterface $sl) {
               print_r($log);
            }
        )
    )
)

The logger_callable will be called for everything there is to log.

2
On

You can log each query using the MongoDB Database Profiler. Use profile level 2. All queries will be logged to the system.profile collection.