‪TYPO3CMS  10.4
DoctrineSqlLogger.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Doctrine\DBAL\Logging\SQLLogger;
21 use Psr\Log\LoggerAwareInterface;
22 use Psr\Log\LoggerAwareTrait;
24 
28 class ‪DoctrineSqlLogger implements SQLLogger, LoggerAwareInterface
29 {
30  use LoggerAwareTrait;
31 
37  protected ‪$queries = [];
38 
44  protected ‪$enabled = true;
45 
49  protected ‪$start;
50 
54  protected ‪$currentQuery = 0;
55 
59  public function ‪startQuery($sql, array $params = null, array $types = null)
60  {
61  if ($this->enabled && ‪MemoryUtility::isMemoryConsumptionTooHigh()) {
62  $this->enabled = false;
63  $this->logger->warning('SQL Logging consumed too much memory, aborted. Not all queries have been recorded.');
64  }
65  if ($this->enabled) {
66  $this->start = microtime(true);
67  $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 7);
68  // remove this method
69  array_shift($backtrace);
70  // remove doctrine execute query
71  array_shift($backtrace);
72  // remove queryBuilder execute
73  array_shift($backtrace);
74  $this->queries[++‪$this->currentQuery] = [
75  'sql' => $sql,
76  'params' => $params,
77  'types' => $types,
78  'executionMS' => 0,
79  'backtrace' => $backtrace
80  ];
81  }
82  }
83 
87  public function ‪stopQuery()
88  {
89  if ($this->enabled) {
90  $this->queries[‪$this->currentQuery]['executionMS'] = microtime(true) - ‪$this->start;
91  }
92  }
93 
97  public function ‪getQueries(): array
98  {
99  return ‪$this->queries;
100  }
101 }
‪TYPO3\CMS\Adminpanel\Log\DoctrineSqlLogger\startQuery
‪startQuery($sql, array $params=null, array $types=null)
Definition: DoctrineSqlLogger.php:55
‪TYPO3\CMS\Adminpanel\Log\DoctrineSqlLogger\$currentQuery
‪int $currentQuery
Definition: DoctrineSqlLogger.php:50
‪TYPO3\CMS\Adminpanel\Log\DoctrineSqlLogger\$start
‪float $start
Definition: DoctrineSqlLogger.php:46
‪TYPO3\CMS\Adminpanel\Log
Definition: DoctrineSqlLogger.php:18
‪TYPO3\CMS\Adminpanel\Log\DoctrineSqlLogger
Definition: DoctrineSqlLogger.php:29
‪TYPO3\CMS\Adminpanel\Log\DoctrineSqlLogger\stopQuery
‪stopQuery()
Definition: DoctrineSqlLogger.php:83
‪TYPO3\CMS\Adminpanel\Log\DoctrineSqlLogger\$queries
‪array $queries
Definition: DoctrineSqlLogger.php:36
‪TYPO3\CMS\Adminpanel\Log\DoctrineSqlLogger\$enabled
‪bool $enabled
Definition: DoctrineSqlLogger.php:42
‪TYPO3\CMS\Adminpanel\Log\DoctrineSqlLogger\getQueries
‪array getQueries()
Definition: DoctrineSqlLogger.php:93
‪TYPO3\CMS\Adminpanel\Utility\MemoryUtility\isMemoryConsumptionTooHigh
‪static bool isMemoryConsumptionTooHigh()
Definition: MemoryUtility.php:39
‪TYPO3\CMS\Adminpanel\Utility\MemoryUtility
Definition: MemoryUtility.php:28