Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

No deprecation log messages with monolog #63479

Copy link
Copy link
@MatthiasKuehneEllerhold

Description

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\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'));

Possible Solution

No response

Additional Context

No response

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.