-
Notifications
You must be signed in to change notification settings - Fork 22
Description
Is your feature request related to a problem?
Currently PhpErrorController::onError always returns false. This causes PHP to continue its normal error handling workflow after Wonolog has already logged the error (e.g. emitting the standard "PHP Notice / Warning" line to error_log or container stdout/stderr). In environments where Wonolog (and its handlers) are the canonical logging path (structured JSON, centralized aggregation, etc.), the duplicate unstructured log line is noisy and undesirable. There is presently no supported way to tell Wonolog: "log it and stop propagation".
When using a custom StreamHandler (e.g. JSON to stdout) every PHP notice/warning/error appears twice:
Raw PHP/SAPI message (e.g. NOTICE: PHP message: PHP Notice: ...)
The structured Wonolog log record for channel PHP-ERROR.
Because PhpErrorController::onError unconditionally returns false, there is no option to short-circuit standard PHP logging once Wonolog has processed the record.
Example
MU plugin configuration:
add_action('wonolog.setup', function (\Inpsyde\Wonolog\Configurator $c) {
$handler = new \Monolog\Handler\StreamHandler('php://stdout', \Monolog\Level::Debug);
$handler->setFormatter(new \Monolog\Formatter\JsonFormatter());
$c->pushHandler($handler);
});
trigger_error('TEST NOTICE '.uniqid(), E_USER_NOTICE);Result (two lines):
NOTICE: PHP message: PHP Notice: TEST NOTICE 68ecd0721ff12 in /app/web/test.php on line 52
{"message":"TEST NOTICE 68ecd0721ff12","channel":"PHP-ERROR","level_name":"NOTICE", ...}
Describe the desired solution
Proposed Feature
Introduce a configuration flag to control propagation of handled PHP errors:
$configurator->suppressNativePhpErrorOutput(); // or
$configurator->stopPhpErrorPropagation();Describe the alternatives that you have considered
Now I have to use this method
set_error_handler(function ($severity, $message, $file, $line) use ($logger) {
if (!(error_reporting() & $severity)) {
// The error is suppressed by the @ operator or the error_reporting mask - let the engine remain silent
return true;
}
$level = mapPhpSeverityToMonologLevel($severity);
$logger->log($level, $message, [
'php_severity' => $severity,
'file' => $file,
'line' => $line,
'source' => 'php_error_handler'
]);
return true; // IMPORTANT: true => standard handler does not write => no duplicates
});Additional context
No response
Code of Conduct
- I agree to follow this project's Code of Conduct