diff --git a/typo3/sysext/core/Classes/Log/Writer/FileWriter.php b/typo3/sysext/core/Classes/Log/Writer/FileWriter.php index 2a70835c1c6a7b34363beb6469fb8b8a2e92a7b2..cbc1fbf33831d44bf080b52c38f476643a0df1f0 100644 --- a/typo3/sysext/core/Classes/Log/Writer/FileWriter.php +++ b/typo3/sysext/core/Classes/Log/Writer/FileWriter.php @@ -34,6 +34,11 @@ class FileWriter extends AbstractWriter */ protected $logFile = ''; + /** + * @var string + */ + protected $logFileInfix = ''; + /** * Default log file path * @@ -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 index 0000000000000000000000000000000000000000..7eaa39e3395d3da46a983d5a84238e12fa37e4f7 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Feature-85236-AddedInfixOptionToDefaultLogFileNamesForFileWriter.rst @@ -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