Magento 2 log all Mysql queries to log file

Edit file vendor/magento/framework/DB/Statement/Pdo/Mysql.php

            return $this->tryExecute(function () use ($params) {
                $writer = new \Zend_Log_Writer_Stream(BP . '/var/log/debugSql.log');
                $logger = new \Zend_Log();
                $logger->addWriter($writer);
                $logger->debug($this->_stmt->queryString);
                $logger->debug(json_encode($params));
                $logger->debug('================');
                return $params !== null ? $this->_stmt->execute($params) : $this->_stmt->execute();
            });

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.