如何在TYPO3后端写入登录?

时间:2017-01-20 11:04:30

标签: 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.');
    }

3 个答案:

答案 0 :(得分:4)

尝试使用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);

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

答案 1 :(得分:2)

默认不记录LogLevel INFO。 (TYPO3 V8)您确实为自己定义了一个记录器,或者将常规LogLevel设置为INFO:

在LocalConfiguration.php中将常规LogLevel设置为INFO:

'LOG' => [
    'writerConfiguration' => [
        \TYPO3\CMS\Core\Log\LogLevel::INFO => [
            'TYPO3\\CMS\\Core\\Log\\Writer\\FileWriter' => [
                'logFile'  => 'typo3temp/var/logs/yourlog_info.log',
            ],
        ],
    ],
],

或者在ext_localconfig.php中输入我的命名空间Taywa \ Artcollection \ Command \ ImportCommandController

$GLOBALS['TYPO3_CONF_VARS']['LOG']['Taywa']['Artcollection']['Command']['ImportCommandController']['writerConfiguration']
= array(
            \TYPO3\CMS\Core\Log\LogLevel::INFO => [
                'TYPO3\\CMS\\Core\\Log\\Writer\\FileWriter' => [
                    'logFile'  => 'typo3temp/var/logs/typo3_artcollection.log',
                ],
            ],
        );

关于此的一些文档:

https://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/Logging/Configuration/Index.html

答案 2 :(得分:1)

您使用的代码不会记录到后端日志模块,但是(默认情况下)会记录到文件typo3temp/var/logs/typo3_*.log或{{1}}。

它是new logging framework

的一部分