doctrine / mongodb-odm

The Official PHP MongoDB ORM/ODM
https://www.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/
MIT License
1.09k stars 504 forks source link

Missing requirements for turning on logging capabilities? #1354

Closed davidloubere closed 8 years ago

davidloubere commented 8 years ago

I tried to turn on query logging but to no avail.

As per the documentation, it would simply require to declare a callable to the Doctrine\ODM\MongoDB\Configuration instance.

FYI, I'm retrieving the instance via the document manager within a controller like so:

$config = $documentManager->getConfiguration();
$config->setLoggerCallable(function(array $log) {
    print_r($log);
});

Am I missing something?

malarzm commented 8 years ago

It should work, we're even using logger in tests to ensure exact number of queries was fired, you can check it out here: https://github.com/doctrine/mongodb-odm/blob/453ef86b8c499b05fefe9b67347b8b9c06e3f176/tests/Doctrine/ODM/MongoDB/Tests/Functional/AtomicSetTest.php#L27

davidloubere commented 8 years ago

So, I presume it is related to my configuration:

"silex/silex": "~1.3",
"doctrine/mongodb": "^1.2",
"doctrine/mongodb-odm": "^1.0",
"symfony/doctrine-bridge": "^2.7",
...

I am using Doctrine through the following Saxulum providers:

"saxulum/saxulum-doctrine-mongodb-odm-provider": "1.*",
"saxulum/saxulum-doctrine-mongodb-odm-manager-registry-provider": "^1.0",

Maybe I should look into that direction.

malarzm commented 8 years ago

Closing because of no update in long time. @davidloubere if there's any news please feel free to update the issue.

fengjunhui commented 5 years ago

davidloubere @davidloubere you must create document manager by "DocumentManager::create($connection, $configuration)",and you only set logger callable on $config.But the log callable should be setted on $connection.When creating document manager, dm's construct founction would not set $configuration into $connection included log callable.And i think it is a BUG. @malarzm @davidloubere @alcaeus @poulikov @jgornick

josefsabl commented 5 years ago

It should work, we're even using logger in tests to ensure exact number of queries was fired, you can check it out here:

https://github.com/doctrine/mongodb-odm/blob/453ef86b8c499b05fefe9b67347b8b9c06e3f176/tests/Doctrine/ODM/MongoDB/Tests/Functional/AtomicSetTest.php#L27

I was looking for a way to replace the old logging feature and was glad I found this reply of yours as that lead me to CommandLogger :-)

anyx commented 5 years ago

setLoggerCallable was removed from configuration in 2.0 version (but still exists in documentation). How I can get queries logs in that version?

alcaeus commented 5 years ago

There is a command logger that you can register. We no longer provide a way to log queries, instead using the APM functionality from the MongoDB driver to log queries. You can find an APM tutorial in the extension docs. We also provide a CommandLogger class that you can register as APM logger and look at queries later.

The ODM bundle for Symfony automatically registers loggers depending on the configuration, so no manual work is necessary there.