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.
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:
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".
Use file logging or sentry logging
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:
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.
$this->logger) and to sys_log.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With