Closed Edwin-Luijten closed 4 years ago
Not by default but php-debugbar includes a doctrine collector, which you can manually register.
Ahh thanks =), I made a serviceprovider wich ads a pdo doctrine collector. Works well so far, ill reference a gist here later on for future reference.
What would be the best place to register this doctrine collector? Maybe in a middleware?
Probably just a service provider, in the boot method.
Cool, that worked. I added the following to my boot method:
$debugStack = new \Doctrine\DBAL\Logging\DebugStack();
\EntityManager::getConnection()->getConfiguration()->setSQLLogger($debugStack);
$debugbar = App::make('debugbar');
$debugbar->addCollector(new \DebugBar\Bridge\DoctrineCollector($debugStack));
if you are using http://www.laraveldoctrine.org/, you could set .env variable
DOCTRINE_LOGGER=LaravelDoctrine\ORM\Loggers\LaravelDebugbarLogger
and it will work.
I'd like to point out that in either case, I'm seeing absolutely nothing in the Query section of the debug bar, Either by registering it manually or by using DOCTRINE_LOGGER.
Is there a different logic with 5.3?
Like @loiclavoie, I too see nothing in the query log from doctrine in the bar. Is there something we need to do to show it?
For anyone else with this issue, the problem is due to a override in the Laravel doctrine package (https://github.com/laravel-doctrine/orm/blob/1.3/src/Loggers/Debugbar/DoctrineCollector.php#L26). The collector their uses the same widget keys as the laravel's eloquent query collector. I've started a proposal issue for it in Laravel Doctrine's repo https://github.com/laravel-doctrine/orm/issues/237.
I worked around the problem for now by simply extending the base DoctrineCollector in DebugBar\Bridge\DoctrineCollector
adding a getter for the debugStack property (getDebugStack
), then extending the debugbar
container definition and added this custom doctrine collector (debugbar::addCollector
instance method). This works because the base DebugBar\Bridge\DoctrineCollector
uses a different set of widget keys than eloquent's query collector.
I also had to eagerly resolve EntityManager
whenever the db
service is resolved to ensure that the logger gets loaded. I did that by using resolving
container method and just forcing the container to also resolve EntityManager
with make
. Not sure if that's the best answer, but it works for now.
I've added doctrin bridge to debugbar in service provider, but i dont see any sql queries, but if call: Debugbar::info(debugbur()->getCollectors()); In "Messages" in array of collectors I do see 'doctrine' collector and it has queries, but why they are not shown? what option did i miss? I'm using doctrine/orm
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this issue is still present on the latest version of this library on supported Laravel versions, please let us know by replying to this issue so we can investigate further. Thank you for your contribution! Apologies for any delayed response on our side.
Is your package able to track doctrine queries?