Log deprecations in Symfony5

Viewed 607

I realized, that my deprecations aren't shown anymore. Now I try to log them via monolog, so that hopefully, when I run my tests the deprecations are logged in a special log. I use symfony 5.3

This is my test monolog configuration:

monolog:
    handlers:
        frontend:
            type: rotating_file
            path: "%kernel.logs_dir%/%kernel.environment%.frontend.log"
            level: debug
            channels: [ "frontend" ]
            max_files: 3
        deprecation:
            type: rotating_file
            path: "%kernel.logs_dir%/%kernel.environment%.deprecations.log"
        deprecation_filter:
            type: filter
            handler: deprecation
            level: info
            channels: [ "php" ]
        main:
            type: rotating_file
            path: "%kernel.logs_dir%/%kernel.environment%.log"
            level: info
            channels: [ "!event", "!frontend", "!deprecation"  ]
            max_files: 3
        console:
            type: console
            process_psr_3_messages: false
            channels: [ "!event", "!doctrine", "!console", "!frontend", !deprecation" ]

I get general messages in my rotating test log, but no deprecation log file is created.

what is wrong with my configuration?

Next try:

monolog:
    handlers:
#        frontend:
#            type: rotating_file
#            path: "%kernel.logs_dir%/%kernel.environment%.log"
#            level: debug
#            channels: [ frontend ]
#            max_files: 3
        main:
            type: rotating_file
            path: "%kernel.logs_dir%/%kernel.environment%.log"
            level: info
            channels: [ "!event", "!frontend", "!deprecations" ]
            max_files: 3
        console:
            type: console
            process_psr_3_messages: false
            channels: [ "!event", "!doctrine", "!console", "!frontend", "!deprecations" ]

and additionally an extra file deprecations.yaml:

monolog:
    channels: [deprecation]
    handlers:
        deprecation:
            type: rotating_file
            channels: [deprecation]
            path: "%kernel.logs_dir%/%kernel.environment%.deprecations.log"

Now I have the deprecations logging into an extra deprecations log file ( nice!) , but they additionally spamming my normal logfile!

What is the correct configuration to get the deprecation only in the deprecation log?

1 Answers

Looks like you should replace "!deprecations" with "!deprecation".

Related