Symfony2在测试环境中禁用日志


Symfony2 disable logs in test environment

如何在测试环境中禁用任何日志?问题与config_test.yml文件中正确的monlog设置有关,该文件继承自config_dev.yml,其中的配置如下所示:

monolog:
    handlers:
        main:
            type:         fingers_crossed
            action_level: error
            handler:      grouped_main
        streamed_main:
            type:   stream
            path:   "%kernel.logs_dir%/%kernel.environment%.log"
            level:  debug
        grouped_main:
            type:    group
            members: [streamed_main]
        console:
            type:   console
            bubble: false
            verbosity_levels:
                VERBOSITY_VERBOSE: INFO
                VERBOSITY_VERY_VERBOSE: DEBUG
            channels: ["!doctrine"]
        console_very_verbose:
            type:   console
            bubble: false
            verbosity_levels:
                VERBOSITY_VERBOSE: NOTICE
                VERBOSITY_VERY_VERBOSE: NOTICE
                VERBOSITY_DEBUG: DEBUG
            channels: ["doctrine"]

您可以使用继承来更改处理程序的类型,甚至级别:

配置测试yml

monolog:
    handlers:
        main:
            type:         fingers_crossed
            action_level: error
            handler:      grouped_main
        streamed_main:
            type:   fingers_crossed
            path:   "%kernel.logs_dir%/%kernel.environment%.log"
            level:  error

您也可以更改为bubble: false

也许你也可以重新考虑不使用日志,你可以把它保存在syslog和其他后端,这样对你来说更方便!