简体   繁体   English

如何使用ZF2 Doctrine MongoDb模块打开日志记录(分析)

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

I've successfully integrated Doctrine MongoDB module in Zend Framework 2 and now I need to keep track of each query to MongoDB. 我已经在Zend Framework 2中成功集成了Doctrine MongoDB模块,现在我需要跟踪对MongoDB的每个查询。 Does anybody know how to turn on logging? 有人知道如何打开日志记录吗?

You can log each query using the MongoDB Database Profiler . 您可以使用MongoDB数据库分析器记录每个查询。 Use profile level 2. All queries will be logged to the system.profile collection. 使用配置文件级别2。所有查询将记录到system.profile集合中。

I just proposed a pull request on the DoctrineMongoODMModule to integrate the logging configuration option of MongoDB ODM. 我刚刚在DoctrineMongoODMModule上提出了一个拉取请求 ,以集成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-mongo-odm.global.php文件中:

'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. logger_callable将被调用以记录所有内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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