【发布时间】:2020-04-14 17:14:24
【问题描述】:
我想从 Symfony 4.4 升级。到 5.0。所以我必须检查代码中的弃用。 symfony migration guide 说我必须使用 web 开发工具栏,但是在我的 API 应用程序中没有工具栏的前端。
如何配置 symfony/monolog 以将弃用警告记录到日志文件中?
更新 我创建了一个最小的示例:
composer create-project symfony/website-skeleton:4.3.99
TestController.php
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* Class ApiController
* @package App\Controller
* @Route("", defaults={"_format"="json"})
*
*/
class TestController extends AbstractController
{
/**
* @Route("/test", name="test")
* @param Request $request
* @return Response
*/
public function test(Request $request): Response
{
@trigger_error(sprintf('DEMO DEPRECATION', __METHOD__), E_USER_DEPRECATED);
return $this->json([
'test' => '1'
]);
}
}
独白.yml
monolog:
handlers:
main:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
channels: ["!event"]
# uncomment to get logging in your browser
# you may have to allow bigger header sizes in your Web server configuration
#firephp:
# type: firephp
# level: info
#chromephp:
# type: chromephp
# level: info
console:
type: console
process_psr_3_messages: false
channels: ["!event", "!doctrine", "!console"]
deprecation_stream:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.deprecations.log"
deprecation_filter:
type: filter
handler: deprecation_stream
max_level: info
channels: ["php"]
运行服务器
bin/console server:run
但是 dev.deprecations.log 仍然是空的。
【问题讨论】:
-
开发模式下的调试工具栏似乎捕获了这些弃用通知,因为它们没有出现在标准日志文件中。我怀疑编译器传递正在拦截它们。
-
我在github上创建了一个错误报告/问题github.com/symfony/symfony/issues/35367
标签: php symfony monolog deprecation-warning