Project

General

Profile

Actions

Bug #94043

closed

Incorrect usage of PSR-3 logger

Added by Larry Garfield almost 3 years ago. Updated almost 3 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Logging
Start date:
2021-05-03
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
11
PHP Version:
Tags:
Complexity:
hard
Is Regression:
Sprint Focus:

Description

The logger service is frequently used like this:

```
$this->logger->notice('The singleton "' . $classSchema->getClassName() . '" needs a prototype in the constructor.');
```

That is incorrect according to PSR-3. The string for the message is supposed to be static. If it has variable data (like the class name here), the string should have a placeholder and the value provided in the `$context` array. That is, it should be more like this:

```
$this->logger->notice('The singleton "{class}" needs a prototype in the constructor.', ['class' => $classSchema->getClassName()]);
```

This is similar in structure and concept to sprintf() and prepared statements for SQL, and for the similar reasons.

1. It allows the separate data value to be escaped if necessary in an output-dependent way, rather than inlined without escaping. (Technically not doing so is an injection vector, though I've not seen a real vector in here yet.)
2. The message may be extracted and translated in order to provide localization of log messages, especially if they are shown on screen.
3. It allows for more robust tracking of what errors are being generated. For instance, one could search a DB table of log messages for the template string.

I am not sure what all the logging backend is doing right now, so it may be more complicated than just fixing all the call sites. But fixing all the call sites would be a really good set of newbie-tasks once we're confident the backend is ready for it.


Related issues 5 (0 open5 closed)

Related to TYPO3 Core - Feature #85506: Integrate monolog as logging frameworkRejectedBenjamin Franzke2018-07-07

Actions
Related to TYPO3 Core - Bug #94315: Use PSR-3 interpolationClosed2021-06-11

Actions
Related to TYPO3 Core - Task #94344: Move PSR-3 logger to its own tableClosed2021-06-14

Actions
Related to TYPO3 Core - Task #94352: Tidy up logging frameworkClosed2021-06-15

Actions
Related to TYPO3 Core - Epic #94356: Embrace PSR-3Closed2021-06-11

Actions
Actions

Also available in: Atom PDF