【问题标题】:How to display warning and deprecated messages in Laravel如何在 Laravel 中显示警告和弃用消息
【发布时间】:2022-01-26 14:56:31
【问题描述】:

如果我编写一些带有弃用通知的 PHP 代码,它会显示在本地环境中。

示例:index.php

<?php

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

super('sy', 1);

exit;

显示:

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

这很好。

但是 Laravel 控制器中完全相同的代码不会显示,也不会存储在任何日志文件中。 我将配置 app.env 设置为“local”,将 app.debug 设置为 true,将 app.log_level 设置为“debug”。 知道我错过了什么吗?

【问题讨论】:

    标签: laravel log-level


    【解决方案1】:

    根据docs

    记录弃用警告

    PHP、Laravel 和其他库经常通知他们的用户一些 他们的一些功能已被弃用,并将在未来被删除 版本。如果您想记录这些弃用警告,您可以 在您的 应用的config/logging.php配置文件:

    'deprecations' => env('LOG_DEPRECATIONS_CHANNEL', 'null'),
    
    'channels' => [
        ...
    ]
    

    或者,您可以定义一个名为 deprecations 的日志通道。如果一个日志通道 如果存在此名称,它将始终用于记录弃用:

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

    【讨论】:

    • 感谢您指点文档!不幸的是,它不能很好地工作。一些弃用总是被记录,一些有时被记录,一些从未被记录。我会坚持使用 phpstan 来检测已弃用的代码。
    猜你喜欢
    • 2016-01-25
    • 1970-01-01
    • 1970-01-01
    • 2017-01-08
    • 2023-03-23
    • 2013-05-14
    • 2016-05-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多