Review main Abandoned

48174[WIP][FEATURE] Replace logging framework with monolog

Susi Moog CR 0 V 0 Nightmare +678 −3402 updated 02/28/20, 09:47

Commit message

This patch introduces the requirement for monolog/monolog
which will replace the former logging framework of TYPO3.

Both the former framework and monolog are PSR-3 compatible,
thus there is no change in actual log calls. However, there
is a change regarding the configuration of monolog in TYPO3.

The goal is to embrace the idea of channels and looking at
the configuration like symfony does. To understand why things
are configured the way they are, one has to understand the
concept of monolog.

There are loggers, channels, handlers, processors and formatters.
While this commit message can't go into details about all these
things, it will roughly explain how they work together.

A logger is the instance that represents PSR-3, along with the
callable log methods (error, warning, debug and such).

Each logger represents a channel. But a channel is not the name
of a logger as different loggers can represent (write into) the
same channel. A channel is like a category. While most log entries
are fine to be written into a default channel, a failed login
attempt should be written into a security channel. A channel does
not define where a log is written to, it only categorizes the
log entries.

Then there are handlers. They define how and where a log entry
is written (to). The default handler of TYPO3 is a StreamHandler
that writes log files to typo3temp/var/logs/typo3.log.
While a handler defines how and where a log entry is written (to),
the so to subscribed channels define which log entries are handles
by the handler. TYPO3 defines a default channel which – along with
the default StreamHandler - is some kind of a fallback logging
strategy.

Processors are actually just callbacks that work on the log entry
and alter it. An example is a uid processor, that adds a unique
id to all log entries.

Formatters are objects that define how the log entry is formatted.
The default formatter is a line formatter, which is suitable for
logging to files.

As the main concepts of monolog are embraced, the official docs
of monolog are a must read to fully understand the possibilities
and why the configuration works the way it does.

About the configuration:
$GLOBALS['TYPO3_CONF_VARS']['LOG'] is still the entry point for
the configuration of the logging framework. However, the available
keys have changed.

The following keys do exist:
$GLOBALS['TYPO3_CONF_VARS']['LOG']['handlers']
$GLOBALS['TYPO3_CONF_VARS']['LOG']['processors']
$GLOBALS['TYPO3_CONF_VARS']['LOG']['loggers']

$GLOBALS['TYPO3_CONF_VARS']['LOG']['handlers'] defines all
available handlers in the installation and the configration
does no differ much from the one of the former logging framework.

$GLOBALS['TYPO3_CONF_VARS']['LOG']['processors'] are globally
availbale log entry processors. As a default there are no global
processors defined but it's likely to change as global processors
are a great way to add extra information to the log entry.
Backend user id, frontend user id, unique request id and many more
are examples of additional data that might be added globally via
processors.

$GLOBALS['TYPO3_CONF_VARS']['LOG']['loggers'] is a simple mapping
of class name to channel name. By default, all classes that do not
have a mapping here, will get a logger instance that logs to the
default channel. This configuration is a very simple represen-
tation of the dependency injection configuration of symfony.

As TYPO3 does not have such a sophisticated dependency injection
and dependency configuration like symfony, the possibilites are
rather limited at the moment. The goal is to define loggers by
extension or namespace in the future.

Although this is not possible at the moment, the implementation
of monolog still drastically imporves the possibilites to
properly log what's going on and especially where to log to.

todo:
- documentation
- config migration wizard

Review

  • Code review CR 0

    Imported before Forger kept the single votes, the next import adds them.

  • Verified V 0

    Imported before Forger kept the single votes, the next import adds them.

Issues 1

Files 54

Show 34 more files