Last active
May 11, 2022 12:41
-
-
Save kitzberger/32bbbc3e54c514a882226514f8c9dd19 to your computer and use it in GitHub Desktop.
TYPO3: logging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Don't log any deprecations | |
unset($GLOBALS['TYPO3_CONF_VARS']['LOG']['TYPO3']['CMS']['deprecations']); | |
// Log only errors and higher (default is 'warning') | |
$GLOBALS['TYPO3_CONF_VARS']['LOG']['writerConfiguration'] = [ | |
\TYPO3\CMS\Core\Log\LogLevel::ERROR => [ | |
\TYPO3\CMS\Core\Log\Writer\FileWriter::class => [], | |
], | |
]; | |
// Enable deprecation log for TYPO3 9+ | |
$logWriterConf = [ | |
'TYPO3' => [ | |
'CMS' => [ | |
'deprecations' => [ | |
'writerConfiguration' => [ | |
\TYPO3\CMS\Core\Log\LogLevel::NOTICE => [ | |
\TYPO3\CMS\Core\Log\Writer\FileWriter::class => [ | |
'disabled' => false, | |
], | |
], | |
], | |
], | |
], | |
], | |
]; | |
$GLOBALS['TYPO3_CONF_VARS']['LOG'] = array_replace_recursive($GLOBALS['TYPO3_CONF_VARS']['LOG'], $logWriterConf); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$logWriterConf = [ | |
// Set log config for namespace \Vendor\MyExtension\Controller | |
'Vendor' => [ | |
'MyExtension' => [ | |
'Controller' => [ | |
'writerConfiguration' => [ | |
\TYPO3\CMS\Core\Log\LogLevel::INFO => [ | |
\TYPO3\CMS\Core\Log\Writer\FileWriter::class => [ | |
// TYPO3 >= 9: logging to var/log/typo3_myext-controller_<md5>.log | |
'logFileInfix' => 'myext-controller' | |
// TYPO3 < 9: logging to html/typo3temp/var/logs/myext-controller.log | |
'logFile' => 'typo3temp/var/logs/myext-controller.log' | |
], | |
], | |
], | |
], | |
], | |
], | |
]; | |
$GLOBALS['TYPO3_CONF_VARS']['LOG'] = array_replace_recursive($GLOBALS['TYPO3_CONF_VARS']['LOG'], $logWriterConf); | |
// Set logging for exceptions during rendering of single content elements: | |
$GLOBALS['TYPO3_CONF_VARS']['LOG']['TYPO3']['CMS']['Frontend']['ContentObject']['Exception']['ProductionExceptionHandler']['writerConfiguration'] = [ | |
\TYPO3\CMS\Core\Log\LogLevel::ERROR => [ | |
\TYPO3\CMS\Core\Log\Writer\FileWriter::class => [ | |
'logFileInfix' => 'exceptions' | |
], | |
], | |
]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// TYPO3 9+ | |
use Psr\Log\LoggerAwareInterface; | |
use Psr\Log\LoggerAwareTrait; | |
use TYPO3\CMS\Core\Log\LogLevel; | |
class CleanupBeUsers extends Command implements LoggerAwareInterface | |
{ | |
use LoggerAwareTrait; | |
function xxx() | |
{ | |
$this->logger->log(LogLevel::INFO, $message); | |
} | |
} | |
// Pre TYPO3 9 | |
/** @var \TYPO3\CMS\Core\Log\Logger */ | |
$this->logger = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Log\LogManager::class)->getLogger(__CLASS__); | |
$this->logger->log(\TYPO3\CMS\Core\Log\LogLevel::ERROR, $message); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment