Review main Ready for review

98155[FEATURE] Configure Monolog handlers and inject log writer dependencies

Benni Mack CR 0 V 0 Expert +1199 −9 updated 11/28/26, 15:10

Commit message

Since TYPO3 uses Monolog to process log records, its handlers,
formatters and processors can now be configured for TYPO3 logging:

- $GLOBALS['TYPO3_CONF_VARS']['LOG']['handlers'] defines handlers by a
  name: class, named constructor arguments, minimum level, formatter
  and processors. A handler is created once and shared by all loggers.
- $GLOBALS['TYPO3_CONF_VARS']['LOG']['channels'] assigns handlers to a
  logger name or a prefix of logger names, "default" to all loggers.
  The handlers of all matching channels are combined, unless a channel
  sets "inherit" to false.

This allows to send log records to any target Monolog supports without
a TYPO3 specific log writer, e.g. as JSON lines to stderr, where
container platforms collect them.

The new configuration works side by side with "writerConfiguration":
a logger gets its writers from there and its handlers from the
channels, none of them replaces the other. The default configuration
keeps the FileWriter and defines no handlers, so nothing changes for
existing installations. The changelog explains the consequences and a
step by step migration from writers to handlers.

LogManager adds the configured handlers to the loggers with
Logger::addHandler(). They receive the request ID in the extra data of
the record, also for levels below the configured writers, and the
changes of configured log processors.

Log writers and Monolog handlers, formatters and processors registered
as services are collected into a service locator by the new
LogWriterPass. When they are configured without arguments or options,
LogManager takes them from that locator, so they can use constructor
injection. Writers taken from the container are not shared, unless the
class implements SingletonInterface.

A singleton writer configured without options is now the shared
instance of the container. Before, LogManager passed an empty options
array to GeneralUtility::makeInstance(), which then created a new
instance for every logger, and code reading the writer from the
container, like the admin panel with its InMemoryLogWriter, did not see
the records.

Loggers created while TYPO3 is booted, before the container exists,
leave out writers and handlers that need dependency injection, without
a warning. Loggers created later get them.

This replaces the approach of change 94827, which introduced a
configuration API for log writers that is not needed once writers can
be replaced by Monolog handlers.
Show more Show less

Test this change

Run a command in your clone of the TYPO3 Core. Then try what the change does and vote on Verified in Gerrit. How to review a patch

Check out patch set 3
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/55/98155/3 && git checkout FETCH_HEAD
Cherry-pick onto main
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/55/98155/3 && git cherry-pick FETCH_HEAD

Review

  • Code review CR 0 Needs a vote
  • Verified V 0 Needs a vote
    • core-ci +1 CI

Relation chain 3

  1. 98081[FEATURE] Capture log records for a scoped part of a request Based on this change Benni Mack → main Expert +1132 −444 CR 0 V 0 Merge conflict
  2. 98155 [FEATURE] Configure Monolog handlers and inject log writer dependencies This change

  3. 98154[FEATURE] Use Monolog as backend of the TYPO3 logger This change is based on it Benni Mack → main Hard +629 −23 CR 0 V 0

Merge conflicts 19

Show 14 more changes Show less

Issues 3

Files 12

Review log 36

  1. Benni Mack uploaded patch set 1 11/28/26, 12:51

  2. core-ci voted on patch set 1 V +1 11/28/26, 13:00 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/115838

  3. Benni Mack uploaded patch set 2 V +1 11/28/26, 14:06

  4. core-ci voted on patch set 2 V +1 11/28/26, 14:21 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/115850

  5. Benni Mack uploaded patch set 3 V +1 11/28/26, 14:57

  6. core-ci voted on patch set 3 V +1 11/28/26, 15:10 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/115858