Magento 2:记录慢速查询


10

回到M1,您可以通过修改以下变量来记录慢速查询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';

所以我想知道如何在M2中做到这一点?我已经发现了一些有趣的东西,在lib/internal/Magento/Framework/DB/Logger/LoggerAbstractlib/internal/Magento/Framework/DB/Logger/File,但我不是100%肯定该如何处理这个。

Answers:


14

app/etc/di.xml 设置了以下首选项

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

添加您自己的模块以将偏好设置更改为您提到的文件记录器

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

您还应该能够通过相同的方式更改参数 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>

甜蜜,我知道它会涉及一些DI更改。很高兴知道。非常感谢
拉斐尔(Raphael)在Digital Pianism上2013年

嗨,我相信参数“ logAllQueries”和“ logCallStack”的“ xsi:type”应该是“ boolean”而不是“ bool”。
Andrew C. Stayart '17

谢谢@AndrewStayart-固定的。像2.2长相可能会在商店里一些变化github.com/magento/magento2/blob/2.2.0-preview/app/etc/...
克里斯托夫在Fooman
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.