【问题标题】:Exclude 404 from monolog从独白中排除 404
【发布时间】:2019-12-18 23:54:39
【问题描述】:

我正在尝试从独白中排除 404 错误,以免在机器人抓取我的网站时发送垃圾邮件。 所以我尝试了这个文档:https://symfony.com/blog/new-in-symfony-4-1-ignore-specific-http-codes-from-logs,但如果我的网址不正确,我总是会收到来自 monolog 的 Slack ...

我做错了什么? 是错误的程度吗?

规格:

  • Symfony 4.3.2
  • 独白包^3.4

感谢您提供的任何帮助。

    slack:
        type:        slack
        token:       '%env(SLACK_TOKEN)%'
        channel:     'it-erreurs'
        bot_name:    'Erreurs'
        icon_emoji:  ":heavy_check_mark:"
        level:       notice
        channels:    ['symfony']
        include_extra: true

    filter_for_errors:
        type: fingers_crossed
        action_level: notice
        handler: file_log
        excluded_http_codes: [403, 404, { 400: ['^/foo', '^/bar'] }]

    file_log:
        type: stream
        path: "%kernel.logs_dir%/%kernel.environment%.log"

    deduplicated:
        type:    deduplication
        handler: grouped
        time: 30

    grouped:
        type:    group
        members: [slack, filter_for_errors]

【问题讨论】:

    标签: php symfony4 monolog


    【解决方案1】:

    我遇到了同样的问题,最后我是这样解决的:

            slack_errors:
                type:         fingers_crossed
                action_level: error
                excluded_404s:
                    - ^/
                handler:      slack_errors_handler
            slack_errors_handler:
                type:        slack
                token:       '%env(SLACK_TOKEN)%'
                channel:     '%env(SLACK_ERROR_CHANNEL)%'
                bot_name:    '%env(SLACK_BOT_NAME)%'
                level:       error
                include_extra: true
    

    显然 excluded_http_codes 作为 excluded_404s 选项仅适用于 Fingers_crossed 类型的处理程序。因此,为了避免 Slack 中烦人的 4XX 异常,我在 Slack 处理程序中嵌套了一个 finger_crossed 处理程序。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-08
      • 2016-01-27
      • 2016-07-13
      • 2020-06-17
      • 2012-08-16
      • 1970-01-01
      • 1970-01-01
      • 2017-10-22
      相关资源
      最近更新 更多