You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Upgrading my project to Symfony 8.0 lead to a lot of broken code. I didnt know why, because I never got any deprecations.
Ive set error_reporting(E_ALL) and used the Monolog log handler to write everything to file.
Nothing pops up.
I've registered the logger via Monolog\ErrorHandler::register($logger).
In the Symfony\Component\Console\Application line 558 (in v7.4) a function called trigger_deprecation() is called which should have notified me, that my code will be broken in 8.0, but I never got it!
Turns out: trigger_deprecation() executes @trigger_error().
The monolog error handle compares the (new) value of error_reporting() to E_USER_DEPRECATED and wont log it to file. Because with the @ the error_reporting() is now set to 4437 (instead of E_ALL) before!
So every deprecation CANT get logged with monolog! They only way to get them to log is NOT using Monolog\ErrorHandler::register($logger), instead use this:
$handler = new ErrorHandler($logger);
$handler->registerErrorHandler(handleOnlyReportedErrors: false);
$handler->registerExceptionHandler();
$handler->registerFatalHandler();
How to reproduce
require_once'vendor/autoload.php';
$logger = new \Monolog\Logger(
'logger',
[new \Monolog\Handler\StreamHandler(__DIR__ . '/error.log', \Monolog\Logger::DEBUG)]
);
// DOES NOT LOG ANYTHING:
\Monolog\ErrorHandler::register($logger);
// INSTEAD USE THIS:$handler = new \Monolog\ErrorHandler($logger);
$handler->registerErrorHandler(handleOnlyReportedErrors: false);
$application = new \Symfony\Component\Console\Application();
$application->add(new \Symfony\Component\Console\Command\Command('abc'));
Symfony version(s) affected
7.4
Description
Upgrading my project to Symfony 8.0 lead to a lot of broken code. I didnt know why, because I never got any deprecations.
Ive set
error_reporting(E_ALL)and used the Monolog log handler to write everything to file.Nothing pops up.
I've registered the logger via
Monolog\ErrorHandler::register($logger).In the
Symfony\Component\Console\Applicationline 558 (in v7.4) a function calledtrigger_deprecation()is called which should have notified me, that my code will be broken in 8.0, but I never got it!Turns out:
trigger_deprecation()executes@trigger_error().The monolog error handle compares the (new) value of
error_reporting()toE_USER_DEPRECATEDand wont log it to file. Because with the@theerror_reporting()is now set to 4437 (instead of E_ALL) before!So every deprecation CANT get logged with monolog! They only way to get them to log is NOT using
Monolog\ErrorHandler::register($logger), instead use this:How to reproduce
Possible Solution
No response
Additional Context
No response