‪TYPO3CMS  9.5
InMemoryLogWriter.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 
24 
30 {
31  public static ‪$log = [];
32 
33  private static ‪$memoryLock = false;
34 
42  public function ‪writeLog(‪LogRecord $record): self
43  {
44  // Guard: Locked Writer
45  if (self::$memoryLock === true) {
46  return $this;
47  }
48 
49  // Guard: Memory Usage
50  if (!self::$memoryLock && ‪MemoryUtility::isMemoryConsumptionTooHigh()) {
51  $this->‪lockWriter();
52  return $this;
53  }
54 
55  self::$log[] = $record;
56 
57  return $this;
58  }
59 
63  protected function ‪lockWriter(): void
64  {
65  self::$memoryLock = true;
67  $record = GeneralUtility::makeInstance(
68  LogRecord::class,
69  'TYPO3.CMS.AdminPanel.Log.InMemoryLogWriter',
71  '... Further log entries omitted, memory usage too high.'
72  );
73  self::$log[] = $record;
74  }
75 }
‪TYPO3\CMS\Adminpanel\Log\InMemoryLogWriter\$memoryLock
‪static $memoryLock
Definition: InMemoryLogWriter.php:33
‪TYPO3\CMS\Core\Log\LogLevel\INFO
‪const INFO
Definition: LogLevel.php:85
‪TYPO3\CMS\Adminpanel\Log
Definition: DoctrineSqlLogger.php:4
‪TYPO3\CMS\Core\Log\LogRecord
Definition: LogRecord.php:21
‪TYPO3\CMS\Adminpanel\Log\InMemoryLogWriter
Definition: InMemoryLogWriter.php:30
‪TYPO3\CMS\Adminpanel\Utility\MemoryUtility\isMemoryConsumptionTooHigh
‪static bool isMemoryConsumptionTooHigh()
Definition: MemoryUtility.php:38
‪TYPO3\CMS\Adminpanel\Log\InMemoryLogWriter\$log
‪static $log
Definition: InMemoryLogWriter.php:31
‪TYPO3\CMS\Adminpanel\Log\InMemoryLogWriter\writeLog
‪self writeLog(LogRecord $record)
Definition: InMemoryLogWriter.php:42
‪TYPO3\CMS\Core\Log\Writer\AbstractWriter
Definition: AbstractWriter.php:24
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Adminpanel\Utility\MemoryUtility
Definition: MemoryUtility.php:27
‪TYPO3\CMS\Adminpanel\Log\InMemoryLogWriter\lockWriter
‪lockWriter()
Definition: InMemoryLogWriter.php:63
‪TYPO3\CMS\Core\Log\LogLevel
Definition: LogLevel.php:21