10

Back in M1 you could log the slow queries by modifying the following variables in lib/Varien/Db/Adapter/Pdo/Mysql.php :

/**
  * Write SQL debug data to file
  *
  * @var bool
  */
 protected $_debug               = false;
 /**
  * Minimum query duration time to be logged
  *
  * @var unknown_type
  */
 protected $_logQueryTime        = 0.05;
 /**
  * Log all queries (ignored minimum query duration time)
  *
  * @var bool
  */
 protected $_logAllQueries       = false;
 /**
  * Add to log call stack data (backtrace)
  *
  * @var bool
  */
 protected $_logCallStack        = false;
 /**
  * Path to SQL debug data log
  *
  * @var string
  */
 protected $_debugFile           = 'var/debug/sql.txt';

So I'm wondering how can I do that in M2? I've found some interesting stuff in lib/internal/Magento/Framework/DB/Logger/LoggerAbstract as well as lib/internal/Magento/Framework/DB/Logger/File but I ain't 100% sure how to tackle this.

1 Answer 1

14

app/etc/di.xml has the following preference set

<preference for="Magento\Framework\DB\LoggerInterface" type="Magento\Framework\DB\Logger\Quiet"/>

Add your own module to change the preference to the file logger you mentioned with

<preference for="Magento\Framework\DB\LoggerInterface" type="Magento\Framework\DB\Logger\File"/>

You should also be able to change the params via the same di.xml

<type name="Magento\Framework\DB\Logger\File">
    <arguments>
        <argument name="debugFile" xsi:type="string">debug/db-custom.log</argument>
        <argument name="logAllQueries" xsi:type="boolean">false</argument>
        <argument name="logQueryTime" xsi:type="number">0.01</argument>
        <argument name="logCallStack" xsi:type="boolean">false</argument>
    </arguments>
</type>
3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.