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