Errors, logging and performance · Question 1 of 12
How does your own service class get a logger in TYPO3 v14?
2 answers are correct. Easy
Show answer
Answer
- C Through constructor injection of a parameter of type Psr\
Log\ LoggerInterface - D Through the LoggerAwareInterface together with the LoggerAwareTrait
Explanation
TYPO3 relies on the PSR-3 logging standard. The simplest way is to have a Psr\ passed in via constructor injection; TYPO3 then creates a logger that uses the class name as its channel. Alternatively the class implements LoggerAwareInterface and uses the LoggerAwareTrait; the logger is then set automatically and is available in $this->logger. After that, something like $this->logger->warning('Import failed', ['file' => $file]); is enough. Where the messages are written is decided by the logging configuration via writers – which is why you do not create writers yourself in the code.