Frontend plugin exceptions not generating backend notifications in TYPO3
0 reputation · 14 Feb 2024, 09:10 UTC
0 reputation · 14 Feb 2024, 09:10 UTC
The goal is to ensure that administrators are alerted in the TYPO3 backend Notification Center when an unhandled exception occurs in a frontend plugin, without contributing to notification noise.
Currently, frontend exceptions are written to the sys_log table via the core logging framework, but they do not automatically trigger a backend notification. Administrators must manually check the Log module or the Status Report to become aware of these issues. This behavior creates a gap between error detection and operational awareness, especially when log levels are tuned to file‑based writers for DEBUG/INFO while only WARNING+ entries populate sys_log.
Constraints include preserving the existing log writer configuration (e.g., rotating file logs for low‑severity messages), avoiding excessive flash messages that could obscure critical alerts, and respecting TSconfig options such as hideNotification that may suppress notifications for specific modules or user groups. It is also unclear whether extending the logging framework with a notification listener, configuring the Notification Center to poll sys_log entries above a certain severity, or creating a dedicated Scheduler task would be the most appropriate solution.
Which configuration options exist to route frontend exceptions to the backend notification system? How can log level thresholds be set so that only exceptions of WARNING or higher generate a backend notification? What TSconfig or extension settings can suppress low‑priority noise while still ensuring critical frontend errors are surfaced?
31775 reputation · 14 Feb 2024, 13:42 UTC
No built-in TYPO3 configuration routes unhandled frontend plugin exceptions to the backend Notification Center, and JavaScript errors from the browser will not reach the PHP LogManager or sys_log without an explicit client-to-server reporting path.
Confirmed facts:
Likely explanation for the gap you describe:
This changes the recommendation completely. Confirm the origin of the exception:
Keep existing file writers for DEBUG/INFO and ensure WARNING+ reaches sys_log:
Client errors must be reported explicitly:
Missing diagnostic detail needed: Is the exception a PHP exception thrown during plugin execution on the server, or a JavaScript error in the browser? The remediation path is different for the two cases.
Use comments to ask for clarification. Post a solution as an answer.
31,775 reputation · 14 Feb 2024, 16:01 UTC
You can bridge the gap between the DatabaseWriter (which populates sys_log) and the NotificationCenter by creating a small decorator writer that forwards log records of a given severity to \TYPO3\CMS\Core\Notification\NotificationService. This keeps your existing file writers untouched while ensuring only WARNING+ entries trigger a backend notification.
use TYPO3\CMS\Core\Log\LogLevel;
use TYPO3\CMS\Core\Log\Writer\WriterInterface;
use TYPO3\CMS\Core\Notification\NotificationService;
class NotificationForwardingWriter implements WriterInterface
{
private WriterInterface $delegate;
private NotificationService $notificationService;
private int $threshold;
public function __construct(WriterInterface $delegate, NotificationService $notificationService, int $threshold = LogLevel::WARNING)
{
$this->delegate = $delegate;
$this->notificationService = $notificationService;
$this->threshold = $threshold;
}
public function write(array $record, bool $inherit = true): void
{
// forward to the original writer (e.g. DatabaseWriter)
$this->delegate->write($record, $inherit);
// if the level meets the threshold, create a notification
if ($record['level'] >= $this->threshold) {
$this->notificationService->addNotification(
(string) $record['message'],
NotificationService::NOTIFICATION_TYPE_ERROR,
$record['data'] ?? []
);
}
}
}
Register this writer in Configuration/Services.yaml and replace the default DatabaseWriter entry:
services:
TYPO3\CMS\Core\Log\Writer\Database:
public: false
My\Extension\Log\Writer\NotificationForwardingWriter:
arguments:
$delegate: '@TYPO3\CMS\Core\Log\Writer\Database'
$notificationService: '@TYPO3\CMS\Core\Notification\NotificationService'
$threshold: '%constant(TYPO3\CMS\Core\Log\LogLevel::WARNING)%'
tags:
- { name: 'log.writer', alias: 'Database' }
With this setup, any frontend plugin exception that is logged via the LogManager (e.g. $this->logger->error('Something went wrong')) will appear in sys_log and simultaneously generate a backend notification, while lower‑severity logs continue to go only to your file writers.