Deprecation: #109295 - DatabaseWriter::setLogTable()/getLogTable()
See forge#109295
Description
The methods
set and
get of
\TYPO3\ have been deprecated.
Database is a dedicated writer for the
sys_ table. Its
write method maps
Log fields to the
sys_
schema (
request_,
time_,
component,
level,
message,
data,
tstamp). Allowing an arbitrary table via
set creates a false sense of flexibility: any custom table
would have to replicate the full
sys_ schema to work correctly.
The long-term goal is to make
Database
final and remove
the
$log property entirely.
Impact
Calling
set or
get triggers a PHP
E_ error. This includes passing
log as a
configuration option when
Database is registered via
$GLOBALS, since the
Abstract
constructor resolves options to
set* calls.
Support will be removed in TYPO3 v15.0.
Affected installations
Installations that configure
Database with a custom
log option, or that call
set /
get
directly on a
Database instance.
The extension scanner detects direct calls to
->set and
->get. The more common case — passing
log as a
configuration option via
$GLOBALS — cannot be
detected automatically and requires a manual search for
Database
usages with a
log key.
Migration
Replace
Database with a dedicated writer that extends
\TYPO3\ and implements
write with explicit field mapping for the custom table.
Before (deprecated):
$GLOBALS['TYPO3_CONF_VARS']['LOG']['writerConfiguration'][\Psr\Log\LogLevel::WARNING] = [
\TYPO3\CMS\Core\Log\Writer\DatabaseWriter::class => ['logTable' => 'my_custom_log'],
];
After:
// EXT:my_extension/Classes/Log/Writer/MyCustomTableWriter.php
namespace MyVendor\MyExtension\Log\Writer;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Log\LogRecord;
use TYPO3\CMS\Core\Log\Writer\AbstractWriter;
use TYPO3\CMS\Core\Log\Writer\WriterInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
class MyCustomTableWriter extends AbstractWriter
{
public function writeLog(LogRecord $record): WriterInterface
{
GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionForTable('my_custom_log')
->insert('my_custom_log', [
'created' => (int)$record->getCreated(),
'level' => $record->getLevel(),
'message' => $record->getMessage(),
]);
return $this;
}
}
$GLOBALS['TYPO3_CONF_VARS']['LOG']['writerConfiguration'][\Psr\Log\LogLevel::WARNING] = [
\MyVendor\MyExtension\Log\Writer\MyCustomTableWriter::class => [],
];