如何在 monolog symfony2 日志记录中禁用 security.info 和 security.debug

how to disable security.info and security.debug in monolog symfony2 logging

我经常看到以下日志:

[2015-02-15 09:08:16] request.INFO: Matched route "AppMainBundle_daftar_toko_province" (parameters: "_controller": "App\MainBundle\Controller\ZHomepageController::daftarTokoAction", "provinceName": "DKI JAKARTA", "_route": "AppMainBundle_daftar_toko_province") [] []
[2015-02-15 09:08:16] security.INFO: Populated SecurityContext with an anonymous Token [] []
[2015-02-15 09:08:16] security.DEBUG: Write SecurityContext in the session [] []

在我的 prod.log 中,如何禁用它,我只想查看错误。这是我的独白设置:

monolog:
    handlers:
        main:
            type: fingers_crossed
            action_level: error
            handler: file
            excluded_404s:
                - ^/items/
        file:
            type: stream
            level: debug
        doctrine:
            action_level: debug
            type:  stream
            path:  %kernel.logs_dir%/doctrine_%kernel.environment%.log
            channels: doctrine

您可以定义要记录的频道。使用类似这样的东西来忽略特定频道:

        channels: ["!security"]

如果您只想忽略特定的日志级别,您可以使用 级别参数或在新处理程序中使用两者的组合。

在 symfony4 中(可能还有更高版本) https://symfony.com/doc/current/logging/channels_handlers.html#switching-a-channel-to-a-different-handler

File: \config\packages\dev\monolog.yaml

    monolog:
        handlers:
            main:
                type: stream
                path: "%kernel.logs_dir%/%kernel.environment%.log"
                level: debug
                channels: ["!event", "!request", "!security"]
            # 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", "!request", "!security"]

在我的 symfony4.4 配置 (WebServer) 中,我有 channels: ["!event", "!doctrine", "!console"] 用于 Console 和 channels: ["!event"] 用于 Main