Patrice Rolland
Patrice Rolland

Reputation: 59

how to write log in TYPO3 backend?

I would like to debug backend and need to write some logs. I tried the code belowed but it is not working, it doesn't write anything ! Can you help me ?

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

Upvotes: 3

Views: 4935

Answers (3)

Martin Krung
Martin Krung

Reputation: 1127

Per default LogLevel INFO are not logged. (TYPO3 V8) You have do define a logger for yourself or set the general LogLevel to INFO:

set the general LogLevel to INFO in LocalConfiguration.php:

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

Or in ext_localconfig.php for my namespace 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',
                ],
            ],
        );

Some Documentation about this:

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

Upvotes: 3

pgampe
pgampe

Reputation: 4578

The code you are using does not log to the backend log module, but (by default) to the file typo3temp/logs/typo3.log or typo3temp/var/logs/typo3_*.log.

It is part of the new logging framework.

Upvotes: 1

jokumer
jokumer

Reputation: 2269

Try following PHP, adapt your extension-key and choose error-level

// 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);

Then you will find your message with timestamp and further informations in sys_log table or in BE modul with name 'Log'.

Upvotes: 4

Related Questions