Debugging 在TYPO3后端使用Doctrine SQLLogger记录所有执行的SQL查询

Debugging 在TYPO3后端使用Doctrine SQLLogger记录所有执行的SQL查询,debugging,doctrine,typo3,typo3-8.x,Debugging,Doctrine,Typo3,Typo3 8.x,在许多页面中,记录列表视图的加载时间非常长。为了理解造成这种情况的原因,我们需要分析执行的SQL查询。(最终,我们可能希望后端有一个管理面板) 理论上,DBAL支持挂接SQLLogger,但我们不知道在哪里应该进行适当的类替换/注入 我们确实发现可以修补文件typo3/cms/typo3/sysext/core/Classes/Database/Connection.php,只需创建一个覆盖父级的新方法: /** * Debug all the things * * If the que

在许多页面中,记录列表视图的加载时间非常长。为了理解造成这种情况的原因,我们需要分析执行的SQL查询。(最终,我们可能希望后端有一个管理面板)

理论上,DBAL支持挂接SQLLogger,但我们不知道在哪里应该进行适当的类替换/注入

我们确实发现可以修补文件
typo3/cms/typo3/sysext/core/Classes/Database/Connection.php
,只需创建一个覆盖父级的新方法:

 /**
 * Debug all the things
 *
 * If the query is parametrized, a prepared statement is used.
 * If an SQLLogger is configured, the execution is logged.
 *
 * @param string                                      $query  The SQL query to execute.
 * @param array                                       $params The parameters to bind to the query, if any.
 * @param array                                       $types  The types the previous parameters are in.
 * @param \Doctrine\DBAL\Cache\QueryCacheProfile|null $qcp    The query cache profile, optional.
 *
 * @return \Doctrine\DBAL\Driver\Statement The executed statement.
 *
 * @throws \Doctrine\DBAL\DBALException
 */
public function executeQuery($query, array $params = array(), $types = array(), QueryCacheProfile $qcp = null) {
    $fp = fopen('/var/www/html/logs/mysql.log', 'a'); fwrite($fp, '[QUERY-DOCTRINE] ' . $query . "\n"); fclose($fp);

    return parent::executeQuery($query, $params, $types, $qcp);
}

但这种方法不是真正的可移植性,需要修补composer生成的供应商文件。此外,它还缺乏适当的原始日志记录和复杂的SQLLogger的能力。因此,在某个地方,我们应该能够调用Doctrine
配置
类方法?

您可以修改/扩展连接类,并使数据库层使用或自定义类,以及作为数据库连接配置一部分的wrapperClass配置选项

@medz正在工作,刚刚创建了一个扩展。 需要一些配置文件

$GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['wrapperClass']= \Datenbetrieb\Sqllog\Database\Connection::class;
$GLOBALS['TYPO3_CONF_VARS']['LOG']['Datenbetrieb']['Sqllog']['Database']['Logging']['writerConfiguration'] = array(
    \TYPO3\CMS\Core\Log\LogLevel::DEBUG => array(
        'TYPO3\\CMS\\Core\\Log\\Writer\\FileWriter' => array(),
    ),
);

更新我的帖子,并添加一个指向新ext@medz的链接