Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the logger working in Doctrine MongoDB ODM?

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?

like image 386
Dayson Avatar asked Jul 05 '11 15:07

Dayson


1 Answers

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);
like image 153
Dayson Avatar answered Oct 22 '22 11:10

Dayson