‪TYPO3CMS  11.5
InMemoryLogWriter.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 Psr\Http\Message\ServerRequestInterface;
28 
34 {
38  public static ‪$log = [];
39 
43  private static ‪$memoryLock = false;
44 
52  public function ‪writeLog(‪LogRecord $record): self
53  {
54  // Do not log if CLI, if not frontend, or memory limit has been reached.
56  || !((‪$GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface)
57  || !‪ApplicationType::fromRequest(‪$GLOBALS['TYPO3_REQUEST'])->isFrontend()
58  || self::$memoryLock === true
59  ) {
60  return $this;
61  }
62 
63  // Guard: Memory Usage
65  $this->‪lockWriter();
66  return $this;
67  }
68 
69  self::$log[] = (clone $record)->setMessage($this->‪interpolate($record->‪getMessage(), $record->‪getData()));
70 
71  return $this;
72  }
73 
77  protected function ‪lockWriter(): void
78  {
79  self::$memoryLock = true;
80  $record = GeneralUtility::makeInstance(
81  LogRecord::class,
82  'TYPO3.CMS.AdminPanel.Log.InMemoryLogWriter',
83  LogLevel::INFO,
84  '... Further log entries omitted, memory usage too high.'
85  );
86  self::$log[] = $record;
87  }
88 }
‪TYPO3\CMS\Core\Http\ApplicationType\fromRequest
‪static static fromRequest(ServerRequestInterface $request)
Definition: ApplicationType.php:62
‪TYPO3\CMS\Adminpanel\Log
Definition: DoctrineSqlLogger.php:18
‪TYPO3\CMS\Core\Http\ApplicationType
Definition: ApplicationType.php:52
‪TYPO3\CMS\Core\Log\LogRecord\getData
‪array getData()
Definition: LogRecord.php:187
‪TYPO3\CMS\Core\Log\LogRecord
Definition: LogRecord.php:22
‪TYPO3\CMS\Adminpanel\Log\InMemoryLogWriter
Definition: InMemoryLogWriter.php:34
‪TYPO3\CMS\Core\Log\LogRecord\getMessage
‪string getMessage()
Definition: LogRecord.php:222
‪TYPO3\CMS\Adminpanel\Utility\MemoryUtility\isMemoryConsumptionTooHigh
‪static bool isMemoryConsumptionTooHigh()
Definition: MemoryUtility.php:39
‪TYPO3\CMS\Adminpanel\Log\InMemoryLogWriter\writeLog
‪self writeLog(LogRecord $record)
Definition: InMemoryLogWriter.php:50
‪TYPO3\CMS\Core\Log\Writer\AbstractWriter\interpolate
‪interpolate(string $message, array $context=[])
Definition: AbstractWriter.php:49
‪TYPO3\CMS\Core\Log\Writer\AbstractWriter
Definition: AbstractWriter.php:25
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:43
‪TYPO3\CMS\Adminpanel\Log\InMemoryLogWriter\$memoryLock
‪static bool $memoryLock
Definition: InMemoryLogWriter.php:41
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Adminpanel\Utility\MemoryUtility
Definition: MemoryUtility.php:28
‪TYPO3\CMS\Core\Core\Environment\isCli
‪static bool isCli()
Definition: Environment.php:162
‪TYPO3\CMS\Adminpanel\Log\InMemoryLogWriter\lockWriter
‪lockWriter()
Definition: InMemoryLogWriter.php:75
‪TYPO3\CMS\Adminpanel\Log\InMemoryLogWriter\$log
‪static LogRecord[] $log
Definition: InMemoryLogWriter.php:37
‪TYPO3\CMS\Core\Log\LogLevel
Definition: LogLevel.php:24