Deprecation: #109295 - DatabaseWriter::setLogTable()/getLogTable()
See forge#109295
Description
The methods
set and
get in
\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 to be set via
set created a false sense of
flexibility - any custom table needs to replicate the full
sys_ schema to work correctly.
The long-term goal is to make
Database
final and to
remove the
$log property entirely.
Impact
Calling
set or
get triggers a PHP
E_ error. This also 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 or
get 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 usage 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:
use Psr\Log\LogLevel;
use TYPO3\CMS\Core\Log\Writer\DatabaseWriter;
$GLOBALS['TYPO3_CONF_VARS']['LOG']['writerConfiguration'][LogLevel::WARNING] =
[
DatabaseWriter::class => ['logTable' => 'my_custom_log'],
];
After:
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;
}
}
use Psr\Log\LogLevel;
use MyVendor\MyExtension\Log\Writer\MyCustomTableWriter;
$GLOBALS['TYPO3_CONF_VARS']['LOG']['writerConfiguration'][LogLevel::WARNING] = [
MyCustomTableWriter::class => [],
];