开发者

Getting the logger working in Doctrine MongoDB ODM?

开发者 https://www.devze.com 2023-03-17 05:02 出处:网络
I\'m trying to get the logger working in the Doctrine ODM. // .. some initialization code here ... $mongoConfig->setLoggerCallable(function(array $log){

I'm trying to get the logger working in the Doctrine ODM.

// .. some initialization code here ...

$mongoConfig->setLoggerCallable(function(array $log){
                print开发者_高级运维_r($log);
                die("Mongo Logging Called...");
            });

$dm = \Doctrine\ODM\MongoDB\DocumentManager::create(new \Doctrine\MongoDB\Connection(), $mongoConfig);

Here's the reference: http://www.doctrine-project.org/docs/mongodb_odm/1.0/en/reference/logging.html

I'm querying Documents using the query builder of the document manager.. I'm being to successfully find and persist documents. But the logger call back is NEVER called. What could I be doing wrong?


Found the solution through the #doctrine IRC channel. The connection needs to be passed the configuration separately as the DocumentManager does not apply the configuration passed on to it to the connection it creates. This will be fixed in a future version. Here's how you do it instead -

// setup the mongodb connection
$connection = new \Doctrine\MongoDB\Connection(null, array(), $mongoConfig);

// create the document manager for the connection above
$dm = \Doctrine\ODM\MongoDB\DocumentManager::create($connection, $mongoConfig);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号