[TASK] Deprecate RuntimeCacheWriter
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Log / Writer / RuntimeCacheWriter.php
1 <?php
2 declare(strict_types = 1);
3
4 namespace TYPO3\CMS\Core\Log\Writer;
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 TYPO3\CMS\Core\Cache\CacheManager;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21
22 /**
23 * Log writer that writes log entries into TYPO3 runtime cache
24 * @deprecated Deprecated since TYPO3 9, will be removed in v10
25 */
26 class RuntimeCacheWriter implements WriterInterface
27 {
28 public function __construct()
29 {
30 trigger_error(
31 'RuntimeCacheWriter is deprecated, write your own custom InMemoryLogger instead.',
32 E_USER_DEPRECATED
33 );
34 }
35
36 /**
37 * Writes the log record to TYPO3s runtime cache
38 *
39 * @param \TYPO3\CMS\Core\Log\LogRecord $record Log record
40 * @return \TYPO3\CMS\Core\Log\Writer\WriterInterface $this
41 * @throws \Exception
42 */
43 public function writeLog(\TYPO3\CMS\Core\Log\LogRecord $record)
44 {
45 $cacheManager = GeneralUtility::makeInstance(CacheManager::class);
46 $runtimeCache = $cacheManager->getCache('cache_runtime');
47 $component = str_replace('.', '_', $record->getComponent());
48 $runtimeCache->set(sha1(json_encode($record->getData())), $record, [$component]);
49 return $this;
50 }
51 }