How to display warning and deprecated messages in Laravel

3.3k views Asked by At

If I write some PHP code with a deprecated notice, it displays on a local environment.

Example: index.php

<?php

function super(string $test='', string $essai)
{
    return 'toto';
}

super('sy', 1);

exit;

Displays:

Deprecated: Optional parameter $test declared before required parameter $essai is implicitly treated as a required parameter in /var/www/public/index.php on line 9

Which is fine.

But the exact same code in a controller in Laravel does not display, and is not stored in any log file. I set the config app.env to "local", app.debug to true and app.log_level to "debug". Any idea what I am missing ?

1

There are 1 answers

4
Kenny Horna On

According to the docs:

Logging Deprecation Warnings

PHP, Laravel, and other libraries often notify their users that some of their features have been deprecated and will be removed in a future version. If you would like to log these deprecation warnings, you may specify your preferred deprecations log channel in your application's config/logging.php configuration file:

'deprecations' => env('LOG_DEPRECATIONS_CHANNEL', 'null'),

'channels' => [
    ...
]

Or, you may define a log channel named deprecations. If a log channel with this name exists, it will always be used to log deprecations:

'channels' => [
    'deprecations' => [
        'driver' => 'single',
        'path' => storage_path('logs/php-deprecation-warnings.log'),
    ],
],