[FEATURE] Add infix option for filenames used by FileWriter 98/57198/6
authorMarkus Klein <markus.klein@typo3.org>
Mon, 4 Jun 2018 20:32:26 +0000 (22:32 +0200)
committerFrank Naegler <frank.naegler@typo3.org>
Wed, 18 Jul 2018 20:36:58 +0000 (22:36 +0200)
Resolves: #85236
Releases: master
Change-Id: Iad1047b7a91adee4d0dcad766d5116bea27e34ce
Reviewed-on: https://review.typo3.org/57198
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Jürgen Venne <venne@schaffrath-digital.de>
Tested-by: Jürgen Venne <venne@schaffrath-digital.de>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
typo3/sysext/core/Classes/Log/Writer/FileWriter.php
typo3/sysext/core/Documentation/Changelog/master/Feature-85236-AddedInfixOptionToDefaultLogFileNamesForFileWriter.rst [new file with mode: 0644]

index 2a70835..cbc1fbf 100644 (file)
@@ -35,6 +35,11 @@ class FileWriter extends AbstractWriter
     protected $logFile = '';
 
     /**
+     * @var string
+     */
+    protected $logFileInfix = '';
+
+    /**
      * Default log file path
      *
      * @var string
@@ -90,6 +95,11 @@ class FileWriter extends AbstractWriter
         }
     }
 
+    public function setLogFileInfix(string $infix)
+    {
+        $this->logFileInfix = $infix;
+    }
+
     /**
      * Sets the path to the log file.
      *
@@ -256,7 +266,11 @@ class FileWriter extends AbstractWriter
      */
     protected function getDefaultLogFileName()
     {
-        return Environment::getVarPath() . sprintf($this->defaultLogFileTemplate, substr(GeneralUtility::hmac($this->defaultLogFileTemplate, 'defaultLogFile'), 0, 10));
+        $namePart = substr(GeneralUtility::hmac($this->defaultLogFileTemplate, 'defaultLogFile'), 0, 10);
+        if ($this->logFileInfix !== '') {
+            $namePart = $this->logFileInfix . '_' . $namePart;
+        }
+        return Environment::getVarPath() . sprintf($this->defaultLogFileTemplate, $namePart);
     }
 
     /**
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-85236-AddedInfixOptionToDefaultLogFileNamesForFileWriter.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-85236-AddedInfixOptionToDefaultLogFileNamesForFileWriter.rst
new file mode 100644 (file)
index 0000000..7eaa39e
--- /dev/null
@@ -0,0 +1,34 @@
+.. include:: ../../Includes.txt
+
+=============================================================================
+Feature: #85236 - Added infix option to default log file names for FileWriter
+=============================================================================
+
+See :issue:`85236`
+
+Description
+===========
+
+A new option :php:`logFileInfix` for the :php:`FileWriter` has been introduced.
+This allows to set a different name for the log file that is created by the :php:`FileWriter` without having to define a full path to the file.
+
+The example configuration will use the log file named 'typo3\_special\_<hash>.log'
+for any log message stemming from a class from the :php:`\Vendor\ExtName\` namespace.
+
+.. code-block:: php
+
+   $GLOBALS['TYPO3_CONF_VARS']['LOG']['Vendor']['ExtName']['writerConfiguration'] = [
+     \TYPO3\CMS\Core\Log\LogLevel::INFO => [
+       \TYPO3\CMS\Core\Log\Writer\FileWriter::class => [
+         'logFileInfix' => 'special'
+       ]
+     ]
+   ];
+
+
+Impact
+======
+
+The behaviour for existing :php:`FileWriter` configurations is not changed.
+
+.. index:: LocalConfiguration, ext:core