Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TYPO3: How to configure $GLOBALS['TYPO3_CONF_VARS']['LOG'] correctly

I'm trying to configure logging for one custom class in TYPO3 using the configuration of the logging framework as explained here:

https://docs.typo3.org/m/typo3/reference-coreapi/8.7/en-us/ApiOverview/Logging/Configuration/Index.html

I want to configure logging for every class in

\Aip\Taglialacoda\Task\

With no configuration log messages are written in the log file under typo3temp\var\log.

I have made several attempts like this one:

$GLOBALS['TYPO3_CONF_VARS']['LOG']['Aip']['Taglialacoda']['Task']['writerConfiguration'] = [
    TYPO3\CMS\Core\Log\LogLevel::INFO => [
        TYPO3\CMS\Core\Log\Writer\SyslogWriter::class => [],
    ]
];

The result is always the same: I cannot find messages logged anywhere. The class I wrote is a task so it extends AbstractTask and has its own logger. For this reason I have instantiated another logger (I don't want every task to write into SYS LOG). As I said with no configuration the new logger writes into the log file. If a mistyped configuration is added, the class throws an exception (so the configuration is taken into account). Using the configuration above the log message seems to disappear.

like image 873
Ivano Luberti Avatar asked Nov 15 '25 13:11

Ivano Luberti


1 Answers

Summary:

As far as I know, you are out of luck if you want to log with the logging framework to the sys_log DB table and read this in the "Log" BE module with only core functionality.

Either:

  1. Use extension "logs" (source on GitHub) (disclaimer: this is a third party extension which has been "archived" on GitHub, I do not know if or how long it will be supported). It creates its own backend module "Log" in "Admin Tools".

  2. Use file logging or sentry logging

  3. Write your own LogWriter which will write to the sys_log table in the correct format which is readable by the "Log" BE module.


Your configuration looks good (in general), but will not work as expected.

You may want to make sure first, you know where SyslogWriter will write to. This is explained in the documentation. SyslogWriter will not write to the "sys_log" database table as one might expect but via syslog to the system log. Where this ends up, depends on your configuration. You might want to check your /var/log/messages. This is probably not what you want. Use FileWriter or DatabaseWriter instead.

However, if you use DatabaseWriter, this will not be readable via the "Log" module in the backend, as mentioned in the documentation:

The Admin Tools > Log module is not adapted to the records written by the DatabaseWriter into the sys_log table. If you write such records there, you will not be able to see them using that module. Tip: There’s a tool for viewing such records in the TYPO3 backend at https://github.com/vertexvaar/logs.

I think, it helps if you view the Logging in TYPO3 as 2 separate APIs:

  1. The "old" way of logging to the "sys_log" table with writelog() and viewing this with the "Log" module in the backend. This is no longer recommended in the documentation (though still used in the core).
  2. The newer way to log with the "Logging API" which can log to files, database tables etc. and is also extendable to log to other writers.

The method with 1 is configured by using $GLOBALS['TYPO3_CONF_VARS'][SYS][belogErrorReporting]

So, as already mentioned above, you are out of luck if you want to log with the logging framework (2.) to the sys_log and read this in the "Log" BE module with only core functionality. There is an extension listed https://github.com/vertexvaar/logs. Another possibility is to create your own LogWriter and then write to the sys_log with writelog() in that. This way you would be more flexible in the future.

What I personally also liked very much is the sentry method with sentry-typo3. You might want to have a look at it. But you do have to setup a sentry server. But this is very easily done (at least it worked out of the box for me), but of course that depends on where your site runs.


  • look in the core typo3/sysext/core/Classes/Log/Writer/DatabaseWriter.php You will see that by default "sys_log" is used, but a different schema is required (as also mentioned in the documentation). In my opinion this makes no sense at all, but that is how it is.
  • look in the core typo3/sysext/core/Classes/Log/Writer/SyslogWriter.php. You will see that the logging (in writeLog()) is done with the PHP function syslog. This is not aware of the TYPO3 logging in sys_log.
  • look in the core error and exception handlers, e.g. typo3/sysext/core/Classes/Error/AbstractExceptionHandler.php and you will see that logging is done via logging framework ($this->logger) and to sys_log.
like image 126
Sybille Peters Avatar answered Nov 17 '25 08:11

Sybille Peters



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!