P粉5461798352023-09-06 00:08:27
Try this:
'log' => [ 'traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [ [ 'class' => 'yii\log\FileTarget', 'categories' => ['yii\base\*'], 'levels' => ['error', 'warning','deprecated'], 'logFile' => '@runtime/logs/php_warnings.log', ], ],
Now, PHP warnings will be logged without stopping code execution. However, in order to achieve a completely "silent" way of logging PHP warnings, you need to adjust the settings for PHP error reporting.
Open your PHP configuration file (php.ini).
Find the error_reporting directive and modify it to include E_WARNING. For example:
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE | E_WARNING
By including E_WARNING, you ensure that PHP warnings are logged, but other types of errors are not.
Save the PHP configuration file and restart your web server for the changes to take effect. With these changes, Yii2 will log PHP warnings to the specified log file while allowing execution of the code to continue. You can view the log file (php_warnings.log) to collect and handle PHP warnings.