【问题标题】:Symfony exclude 400 errors from logSymfony 从日志中排除 400 个错误
【发布时间】:2018-04-30 02:34:55
【问题描述】:

我注意到当我抛出 BadRequestHttpException 时,它会被 Monolog 记录。

如何从我的日志中排除特定异常和 HTTP 错误?我的配置如下:

monolog:
    handlers:
        main:
            type: fingers_crossed
            action_level: error
            handler: nested
            excluded_404s:
                - ^/
        nested:
            type: rotating_file
            path: '%kernel.logs_dir%/%kernel.environment%.log'
            level: debug
            max_files: 30

由于这是一个 API 网站,我有很多不应记录的“好”400 错误。

注意:我不想将级别提高到严重

【问题讨论】:

标签: php symfony monolog


【解决方案1】:

目前我找到的唯一解决方案是手动返回视图而不是抛出BadRequestHttpException

$response = new ApiResponse("error", 'There is already a pending request.');
return $this->view($response, 400);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多