[FEATURE] Add RuntimeCacheWriter to Logging Framework 28/56828/2
authorSusanne Moog <susanne.moog@typo3.org>
Sun, 29 Apr 2018 16:07:32 +0000 (18:07 +0200)
committerFrank Naegler <frank.naegler@typo3.org>
Fri, 4 May 2018 10:05:08 +0000 (12:05 +0200)
To be able to easily log request specific information
via the logging framework a new log writer has been
introduced which writes into the TYPO3 runtime cache.

Related: #84044
Resolves: #84894
Releases: master
Change-Id: I0c868d775c9ffe4d4711338778cf6202200c575c
Reviewed-on: https://review.typo3.org/56828
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Joerg Boesche <typo3@joergboesche.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Jan Stockfisch <jan.stockfisch@googlemail.com>
Tested-by: Jan Stockfisch <jan.stockfisch@googlemail.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
typo3/sysext/core/Classes/Log/Writer/RuntimeCacheWriter.php [new file with mode: 0644]
typo3/sysext/core/Documentation/Changelog/master/Feature-84894-AddRuntimeCacheWriterToLoggingFramework.rst [new file with mode: 0644]

diff --git a/typo3/sysext/core/Classes/Log/Writer/RuntimeCacheWriter.php b/typo3/sysext/core/Classes/Log/Writer/RuntimeCacheWriter.php
new file mode 100644 (file)
index 0000000..5ee36a3
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+declare(strict_types = 1);
+
+namespace TYPO3\CMS\Core\Log\Writer;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Core\Cache\CacheManager;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
+/**
+ * Log writer that writes log entries into TYPO3 runtime cache
+ */
+class RuntimeCacheWriter implements WriterInterface
+{
+
+    /**
+     * Writes the log record to TYPO3s runtime cache
+     *
+     * @param \TYPO3\CMS\Core\Log\LogRecord $record Log record
+     * @return \TYPO3\CMS\Core\Log\Writer\WriterInterface $this
+     * @throws \Exception
+     */
+    public function writeLog(\TYPO3\CMS\Core\Log\LogRecord $record)
+    {
+        $cacheManager = GeneralUtility::makeInstance(CacheManager::class);
+        $runtimeCache = $cacheManager->getCache('cache_runtime');
+        $component = str_replace('.', '_', $record->getComponent());
+        $runtimeCache->set(sha1(json_encode($record->getData())), $record, [$component]);
+        return $this;
+    }
+}
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-84894-AddRuntimeCacheWriterToLoggingFramework.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-84894-AddRuntimeCacheWriterToLoggingFramework.rst
new file mode 100644 (file)
index 0000000..f2b5741
--- /dev/null
@@ -0,0 +1,29 @@
+.. include:: ../../Includes.txt
+
+=============================================================
+Feature: #84894 - Add RuntimeCacheWriter to Logging Framework
+=============================================================
+
+See :issue:`84894`
+
+Description
+===========
+
+A new log writer has been added with the ability to write log entries to the TYPO3 runtime cache.
+The writer can be configured via the normal logging framework writer configuration.
+It logs the full log record in the database and uses the given component as cache tag.
+
+Usage
+======
+
+Example usage ::
+
+   $GLOBALS['TYPO3_CONF_VARS']['LOG']['mycomponent'] = [
+       'writerConfiguration' => [
+           \TYPO3\CMS\Core\Log\LogLevel::DEBUG => [
+               \TYPO3\CMS\Core\Log\Writer\RuntimeCacheWriter::class => [],
+           ],
+       ],
+   ];
+
+.. index:: Backend, Frontend, PHP-API, ext:core