如何在TYPO3后端写日志?

Pat*_*and 2 php typo3

我想调试后端,需要写一些日志。我尝试了下面的代码,但是它不起作用,它什么也没写!你能帮助我吗 ?

var $logger;

    public function __construct()
    {
        parent::__construct();
        // desactiver le cache sinoin les FE plugins ne sont pas réactualisé
        // desactivation dans le backend modifie des liens en ajoutant '/no_cache/' devant le lien
        // les liens deviennent inutilisables
        $GLOBALS['TSFE']->set_no_cache();
        $this->logger = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Core\Log\LogManager')->getLogger(__CLASS__);
        $this->logger->info('Everything went fine.');
    }
Run Code Online (Sandbox Code Playgroud)

jok*_*mer 5

尝试使用PHP,调整您的扩展键并选择错误级别

// Log message
$logMessage = 'Everything went fine.';
// Option extension key / module name
$extKey = 'my_extension';
// Error-level: 0 = message, 1 = error (user problem), 2 = System Error (which should not happen), 3 = security notice (admin)
$errorLevel = 0;
// Write sys_log using \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog
$GLOBALS['BE_USER']->simplelog($logMessage, $extKey, $errorLevel);
Run Code Online (Sandbox Code Playgroud)

然后,您将在sys_log表或名称为“ Log”的BE modul中找到带有时间戳的消息以及更多信息。

  • 我必须登录到typo3 管理环境才能让 $GLOBALS['BE_USER'] 不为空! (2认同)