Câu trả lời:
bạn có thể thêm vào một trong các module của bạn trong di.xmltập tin này:
<preference for="Magento\Framework\DB\LoggerInterface" type="Magento\Framework\DB\Logger\File"/>
Các Magento\Framework\DB\Adapter\Pdo\Mysqllớp học được sử dụng để chạy các truy vấn thực tế có thành viên logger Magento\Framework\DB\LoggerInterface.
Theo mặc định, tùy chọn cho phụ thuộc này được đặt trongapp/etc/di.xml
<preference for="Magento\Framework\DB\LoggerInterface" type="Magento\Framework\DB\Logger\Quiet"/>
cái này Magento\Framework\DB\Logger\Quietkhông có gì
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\DB\Logger;
class Quiet implements \Magento\Framework\DB\LoggerInterface
{
/**
* {@inheritdoc}
*/
public function log($str)
{
}
/**
* {@inheritdoc}
*/
public function logStats($type, $sql, $bind = [], $result = null)
{
}
/**
* {@inheritdoc}
*/
public function critical(\Exception $e)
{
}
/**
* {@inheritdoc}
*/
public function startTimer()
{
}
}
thay đổi tùy chọn thành Magento\Framework\DB\Logger\Filevà bạn sẽ thấy các truy vấn đã đăng nhập var/debug/db.log.
Magento đi kèm với 2 logger này (Yên tĩnh và Tệp) mua mặc định, nhưng bạn có thể tự tạo trong trường hợp bạn cần một cách khác để ghi lại các truy vấn.
logAllQueries=truetrước khi chúng được đăng nhập vào tập tin - atwix.com/magento-2/database-queries-logging
LoggerInterfaceđược thực hiện bởi LoggerProxy, không Logger\Quiet, lần lượt lấy tham số từ cấu hình triển khai. Xem câu trả lời của @ Felix ( magento.stackexchange.com/a/201517/60128 ).
Để đặt, logAllQueries=truebạn có thể thêm đoạn mã sau app/etc/di.xmlđể thay đổi __construct()các tham số của Magento\Framework\DB\Logger\File:
<preference for="Magento\Framework\DB\LoggerInterface" type="Magento\Framework\DB\Logger\File"/>
<type name="Magento\Framework\DB\Logger\File">
<arguments>
<argument name="logAllQueries" xsi:type="boolean">true</argument>
</arguments>
</type>
Bạn cũng có thể thay đổi các tham số khác $debugFile, $logQueryTimevà $logCallStacktheo cách đó.
Đây là di.xml của tôi
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Framework\DB\LoggerInterface" type="Magento\Framework\DB\Logger\File"/>
<type name="Magento\Framework\DB\Logger\File">
<arguments>
<argument name="logAllQueries" xsi:type="boolean">true</argument>
<argument name="debugFile" xsi:type="string">sql.log</argument>
</arguments>
</type>
</config>