In magento 1.x I use the n98-magerun
tool to get a log file for all DB Queries:
n98-magerun.phar dev:log:db [--on] [--off]
Is it possible to log database queries in Magento2?
magento2
In magento 1.x I use the n98-magerun
tool to get a log file for all DB Queries:
n98-magerun.phar dev:log:db [--on] [--off]
Is it possible to log database queries in Magento2?
Best Answer
you can add in one of your modules in the
di.xml
file this:The
Magento\Framework\DB\Adapter\Pdo\Mysql
class that is used to run the actual queries has a logger memberMagento\Framework\DB\LoggerInterface
.By default, the preference for this dependency is set in
app/etc/di.xml
this
Magento\Framework\DB\Logger\Quiet
does nothing.change the preference to
Magento\Framework\DB\Logger\File
and you should see the queries logged invar/debug/db.log
.Magento comes with these 2 loggers (Quiet and File) buy default, but you can create your own in case you need a different way of logging queries.