首页 > 解决方案 > Symfony - 抑制特定端点的日志记录

问题描述

我有一个特定的端点,我在其中放置了一个空响应:

/**
 * @Route("/ping", name="ping")
 * @return JsonResponse
 */
public function gcpPingAction(): JsonResponse
{
    return $this->json([], Response::HTTP_OK);
}

在我的日志中,我得到:

在此处输入图像描述

是否可以以某种方式抑制被命中的端点的日志记录?只是为了那个特定的端点..

标签: phpsymfonyloggingrequestsymfony4

解决方案


根据this,您应该可以这样做。

monolog:
    handlers:
        main:
            # ...
            type: fingers_crossed
            handler: ...
            excluded_http_codes: [{ 200: ['^/ping$'] }]

或者像这样

monolog:
    handlers:
        main:
            # ...
            type: fingers_crossed
            handler: ...
            excluded_http_codes:
                - urls:
                    - '^/ping$'

但是,我没有测试它。


推荐阅读