Symfony deprecation log channel

Are you annoyed of too many deprecation warnings in you logs of your symfony app?
Probably yes because it is really a lot of noise.
However deprecation logs are still useful to ensure future compatibility of your app.

So since version 5.1 symfony will log deprecations to a dedicated log channel when it exists and ships with this monolog config:

monolog: channels: - deprecation # Deprecations are logged in the dedicated "deprecation" channel when it exists
Code language: PHP (php)

This is added already in the recipe and ships when installing symfony.

Ok, but the handler for this deprecation channel is not configured, so you have to do this yourself.
How? Add this to your monolog config:

... when@dev: monolog: handlers: main: type: stream path: "%kernel.logs_dir%/%kernel.environment%.log" level: debug channels: ["!event", "!deprecation"] deprecation: type: rotating_file path: "%kernel.logs_dir%/%kernel.environment%.deprecations.log" max_files: 2 channels: [deprecation] console: type: console process_psr_3_messages: false channels: ["!event", "!doctrine", "!console", "!deprecation"] ...
Code language: JavaScript (javascript)

What is happening here?
We declare a new handler for deprecations named deprecation when in dev environment.
This handler listens to the deprecation channel.
We declare it as a rotating file since the assumption is we dont need to keep this log entries for longer.
The other handlers will ignore the deprecation channel by adding a !deprecation to the channel directive.

The deprecation channel was already created and so all deprecations are now not in the main log file but in a dedicated deprecation log file.

For production we dont need to edit configuration since the log level here is info and therefore deprecations will not be considered anyway.