如何在monolog symfony2 logging中禁用security.info和security.debug

时间:2015-02-15 05:11:39

标签: php symfony logging monolog

我经常看到一堆以下日志:

[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

2 个答案:

答案 0 :(得分:1)

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

        channels: ["!security"]

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

答案 1 :(得分:0)

在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"]用于控制台,channels: ["!event"]用于主服务器