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.xml
tập tin này:
<preference for="Magento\Framework\DB\LoggerInterface" type="Magento\Framework\DB\Logger\File"/>
Các Magento\Framework\DB\Adapter\Pdo\Mysql
lớ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\Quiet
khô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\File
và 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=true
trướ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=true
bạ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
, $logQueryTime
và $logCallStack
theo 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>