5

I have multiple production shops with a Symfony base. Now i want to write a log file which logs all deprecations.

I want them to appear in a "deprecated.log" file. These deprecations are read into kibana later.

The Monolog-Readme says

WARNING (300): Exceptional occurrences that are not errors. Examples: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong.

(https://github.com/Seldaek/monolog/blob/master/doc/01-usage.md)

So I tried this config

monolog:
use_microseconds: false
handlers:
    main:
        type: group
        members: [errors, deprecations]
    errors:
        type: error_log
        level: ERROR
    deprecations:
        type: stream
        level: WARNING
        path: '%kernel.logs_dir%/deprecated.log'
        channels: [php]

But the deprecated.log was not generated. What is my mistake? Error-Log seems to work, but not my deprecations.

OptimusCrime
  • 14,662
  • 13
  • 58
  • 96
Patrick
  • 1,562
  • 1
  • 16
  • 33

2 Answers2

4

Was looking around everywhere, this solution was very nice. But even nicer is that since 5.1 there is deprecations channel

As of Symfony 5.1, deprecations are logged in the dedicated "deprecation" channel when it exists
monolog:
channels: [deprecation]
handlers:
    deprecation:
        type: stream
        channels: [deprecation]
        path: php://stderr //or file path like '%kernel.logs_dir%/deprecated.log'
Rokas Lakštauskas
  • 1,078
  • 1
  • 8
  • 17
3

That is because deprecations are of severity level INFO but you set minimum level WARNING, which is above INFO, so deprecations are ignored. Following setting should work for you:

deprecations:
    type: stream
    level: INFO
    path: '%kernel.logs_dir%/deprecated.log'
    channels: [php]
Domino
  • 31
  • 2