gpt4 book ai didi

php - 如何配置 symfony 以记录弃用情况?

转载 作者:行者123 更新时间:2023-12-03 15:16:28 31 4
gpt4 key购买 nike

我想从 Symfony 4.4 升级。到 5.0。所以我必须检查代码中的弃用情况。 symfony migration guide说我必须使用网络开发工具栏,但在我的 API 应用程序中,工具栏没有前端。

如何配置 symfony/monolog 以将弃用警告记录到日志文件中?

更新
我创建了一个最小的例子:

 composer create-project symfony/website-skeleton:4.3.99

测试 Controller .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

打开 http://localhost/test

但是 dev.deprecations.log 仍然是空的。

最佳答案

这是我的弃用日志配置,使用 Monolog:

monolog:
handlers:
# other handlers...

### Deprecation logs
deprecation_stream:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.deprecations.log"

deprecation_filter:
type: filter
handler: deprecation_stream
max_level: info
channels: ["php"]
deprecation_stream指定一个日志文件来记录这些消息。
deprecation_filter指定应该记录哪些消息: info php 中发生的消息 channel (这是发送所有弃用日志消息的地方)。

您可以在整个应用程序范围内启用此应用程序,或者仅在您想要捕获这些消息的任何环境中以这种方式设置它。

关于php - 如何配置 symfony 以记录弃用情况?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59454913/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com