Symfony2 monolog configuration: exclude warning messages from debug messages

2.2k views Asked by At

I use Symfony 2.4 with monolog and have monolog configuration:

monolog:
    channels:               ["voter", "worker"]

    handlers:
        # 'critical' means HTTP 5XX responses.
        critical:
            type:           fingers_crossed
            action_level:   critical
            handler:        critical_group
        # 'error' means HTTP 4XX responses.
        error:
            type:           fingers_crossed
            action_level:   error
            handler:        error_stream
        debug:
            type:           fingers_crossed
            action_level:   debug
            handler:        debug_stream

        critical_group:
            type:           group
            members:        critical_stream

        critical_stream:
            type:           stream
            path:           %kernel.logs_dir%/%kernel.environment%_critical.log
            level:          critical
        error_stream:
            type:           stream
            path:           %kernel.logs_dir%/%kernel.environment%_error.log
            level:          error
        debug_stream:
            type:           stream
            path:           %kernel.logs_dir%/%kernel.environment%_warning.log
            level:          debug

I want to exclude warning messages from debug messages. And warning and debug messages from error messages for cleaner logs. Is any solution for this?

Thanks for any suggestions!

1

There are 1 answers

1
Yassine Guedidi On BEST ANSWER

You can use the filter handler.

Here an additional handler based on your config:

handlers:
    cleaned_debug:
        type: filter
        handler: debug
        accepted_levels: [DEBUG]