Skip to content

Send TYPO3 log files into dedicated log file

It helps a lot to structure the log output of TYPO3 into dedicated files. Be it by extension, for certain code parts or by severity. Since TYPO3 9 LTS there is a new possibility to do that properly.

We have been told that this feature is pretty much unkown in the TYPO3 community. A good reason to shed some details on this neat little thing.

Previously

Your log configuration might have looked like this in the past:

$GLOBALS['TYPO3_CONF_VARS']['LOG']['Reelworx']['RxShariff']['writerConfiguration'] = [
    \TYPO3\CMS\Core\Log\LogLevel::WARNING => [
        \TYPO3\CMS\Core\Log\Writer\FileWriter::class => [
            'logFile' => 'typo3temp/var/log/shariff-4vn34.log'
        ]
    ]
];

As experienced integrator might identify spot on: This has a tiny little drawback.

The log file path is hardcoded.

Does it matter? We said, yes it does, and the reasons are:

  • The location of the var  directory varies depending whether it's a classic or composer installation of TYPO3
  • From version 8 LTS to 9 LTS the path slighty changed from var/logs to /var/log.
    Forgot this to migrate while upgrading? You have two log directories now.
  • Your log file name does not contain an installation dependent hash for security.
  • It is impossible to ship a default log configuration with an extension.
    You don't know where the var folder might be placed.

The evolution

Your new configuration simply changes one line:

- 'logFile' => 'typo3temp/var/log/shariff-4vn34.log'
+ 'logFileInfix' => 'shariff'

This way your final configuration looks like this:

$GLOBALS['TYPO3_CONF_VARS']['LOG']['Reelworx']['RxShariff']['writerConfiguration'] = [
    \TYPO3\CMS\Core\Log\LogLevel::WARNING => [
        \TYPO3\CMS\Core\Log\Writer\FileWriter::class => [
            'logFileInfix' => 'shariff'
        ]
    ]
];

This tells the FileWriter to use the default log file location and name, but add the little extra word shariff into the log file name.

Strike. The log file placement all of a sudden got predictable.

 

This information applies to TYPO3 version 9 and 10 LTS.