#109295Deprecate DatabaseWriter::setLogTable() / getLogTable()
Description
TYPO3\CMS\Core\Log\Writer\DatabaseWriter has setLogTable()/@getLogTable()@ methods allowing users to redirect log output to a custom database table.
This API creates a false sense of flexibility: DatabaseWriter hard-codes field names (request_id, time_micro, component, level, message, data) that are specific to sys_log, so any custom table must replicate the full sys_log schema to work correctly.
This also hinders TYPO3 to make meaningful changes to DatabaseWriter, because that would easily be breaking for users with custom tables.
Proposed change:
- Deprecate
setLogTable()andgetLogTable()inDatabaseWriterwith adeprecated@ annotation and atrigger_error('...', E_USER_DEPRECATED)call. - Add a changelog .rst deprecation note.
- Plan to make DatabaseWriter final and remove $logTable entirely in a future major version.
Migration path for affected users:
If you are using setLogTable() to write to a custom table, implement a dedicated writer by subclassing AbstractWriter and implementing writeLog() with explicit field mapping for your table’s schema. This is also more future-proof since your mapping won’t break when sys_log evolves.
Example:
class MyCustomTableWriter extends AbstractWriter
{
public function writeLog(LogRecord $record): WriterInterface
{
GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionForTable('my_log_table')
->insert('my_log_table', [
'created' => (int)$record->getCreated(),
'level' => $record->getLevel(),
'message' => $record->getMessage(),
]);
return $this;
}
}
// Before:
$GLOBALS['TYPO3_CONF_VARS']['LOG']['writerConfiguration'][\Psr\Log\LogLevel::WARNING] = [
\TYPO3\CMS\Core\Log\Writer\DatabaseWriter::class => ['logTable' => 'my_custom_log'],
];
// After:
$GLOBALS['TYPO3_CONF_VARS']['LOG']['writerConfiguration'][\Psr\Log\LogLevel::WARNING] = [
\MyVendor\MyExtension\Log\Writer\MyCustomTableWriter::class => [],
];