Breaking: #110219 - Log request ID provided by log processor 

See forge#110219

Description 

The unique ID of the current request, used to correlate all log entries written during a single request, was previously passed as constructor argument from \TYPO3\CMS\Core\Log\LogManager to every \TYPO3\CMS\Core\Log\Logger instance, which in turn copied it into each created \TYPO3\CMS\Core\Log\LogRecord .

The request ID is now added to log records at logging time by the new log processor \TYPO3\CMS\Core\Log\Processor\RequestIdProcessor , which LogManager attaches automatically to every logger it creates, for all severity levels covered by the configured log writers. The processor is registered internally on purpose — not via $GLOBALS['TYPO3_CONF_VARS']['LOG'] — so it cannot be removed accidentally by overriding the global processor configuration.

The following method signatures have changed:

  • Logger::__construct() no longer accepts a second $requestId argument, the protected property Logger::$requestId has been removed
  • LogManager::__construct() now expects a \TYPO3\CMS\Core\Core\RequestId object instead of a string, and creates one itself if omitted
  • The protected method LogManager::makeLogger() no longer receives a $requestId argument

The generated log output is unchanged: log records written by configured writers carry the same request ID as before, available via LogRecord::getRequestId() .

Impact 

Instantiating LogManager with a string request ID will raise a PHP \TypeError .

Passing a second argument to the Logger constructor is ignored. Log records created by a manually instantiated Logger — bypassing LogManager — no longer contain a request ID, unless the RequestIdProcessor is attached manually.

Affected installations 

TYPO3 installations with third-party extensions instantiating Logger or LogManager directly with a custom request ID, which is very unlikely. Extensions obtaining loggers via dependency injection, the #[Channel] attribute, LoggerAwareInterface or LogManager->getLogger() are not affected.

Migration 

Obtain loggers through dependency injection or LogManager->getLogger() , which attach the RequestIdProcessor automatically.

For manually created loggers that should add the request ID to their log records, attach the processor explicitly:

use TYPO3\CMS\Core\Core\RequestId;
use TYPO3\CMS\Core\Log\Logger;
use TYPO3\CMS\Core\Log\Processor\RequestIdProcessor;

$logger = new Logger('my.channel');
$logger->addWriter(LogLevel::WARNING, $myWriter);
$logger->addProcessor(LogLevel::WARNING, new RequestIdProcessor(new RequestId()));
Copied!