From fecb95864b6a725f03b83a48ea1929679a77a43d Mon Sep 17 00:00:00 2001 From: Markus Klein <markus.klein@typo3.org> Date: Mon, 4 Jun 2018 22:32:26 +0200 Subject: [PATCH] [FEATURE] Add infix option for filenames used by FileWriter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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> --- .../core/Classes/Log/Writer/FileWriter.php | 16 ++++++++- ...tionToDefaultLogFileNamesForFileWriter.rst | 34 +++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Feature-85236-AddedInfixOptionToDefaultLogFileNamesForFileWriter.rst diff --git a/typo3/sysext/core/Classes/Log/Writer/FileWriter.php b/typo3/sysext/core/Classes/Log/Writer/FileWriter.php index 2a70835c1c6a..cbc1fbf33831 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 000000000000..7eaa39e3395d --- /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 -- GitLab