简体   繁体   中英

Symfony2 disable logs in test environment

How to disable any logs in test environment? Question related to correct monolog setup in config_test.yml file, that inherited from config_dev.yml , where config looks like this:

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"]

You can use the inheritance to change the type of the handler, and even the level:

config_test.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

You can also change to bubble: false

Maybe you can also reconsider no using logs, you can save it on syslog and other backends which can be more convenient to you!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM